-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsandbox.js
executable file
·70 lines (63 loc) · 2.31 KB
/
sandbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// copied from chooseSaveFile function in ng_utils.js and adjusted to support directory selection
function chooseSaveToDirectory (dirName) {
if (!$window.chrome || !chrome.fileSystem || !chrome.fileSystem.chooseEntry) {
return qSync.reject()
}
var deferred = $q.defer()
chrome.fileSystem.chooseEntry({
type: 'openDirectory',
suggestedName: dirName
}, function (chosenDirectory) {
deferred.resolve(chosenDirectory)
})
return deferred.promise
}
function downloadPhoto (photoID) {
var photo = photos[photoID]
var ext = 'jpg'
var mimeType = 'image/jpeg'
var fileName = 'photo' + photoID + '.' + ext
var fullWidth = Math.max(screen.width || 0, $(window).width() - 36, 800)
var fullHeight = Math.max(screen.height || 0, $(window).height() - 150, 800)
var fullPhotoSize = choosePhotoSize(photo, fullWidth, fullHeight)
var inputFileLocation = {
_: 'inputFileLocation',
volume_id: fullPhotoSize.location.volume_id,
local_id: fullPhotoSize.location.local_id,
secret: fullPhotoSize.location.secret
}
FileManager.chooseSave(fileName, ext, mimeType).then(function (writableFileEntry) {
if (writableFileEntry) {
MtpApiFileManager.downloadFile(
fullPhotoSize.location.dc_id, inputFileLocation, fullPhotoSize.size, {
mime: mimeType,
toFileEntry: writableFileEntry
}).then(function () {
// console.log('file save done')
}, function (e) {
console.log('photo download failed', e)
})
}
}, function () {
var cachedBlob = MtpApiFileManager.getCachedFile(inputFileLocation)
if (cachedBlob) {
return FileManager.download(cachedBlob, mimeType, fileName)
}
MtpApiFileManager.downloadFile(
fullPhotoSize.location.dc_id, inputFileLocation, fullPhotoSize.size, {
mime: mimeType
}
).then(function (blob) {
FileManager.download(blob, mimeType, fileName)
}, function (e) {
console.log('photo download failed', e)
})
})
}
//Choose Photo Size
photoSizePreference = 'full' || 'screenSize' || ''
angular.forEach(photo.sizes, function (photoSize) {
//photoSize.w
//photoSize.h
// what else?
}