2014-01-22 10:12:51 +00:00
/ * *
2015-07-12 11:19:57 +00:00
* @ description Takes care of every action an album can handle and execute .
* @ copyright 2015 by Tobias Reich
2014-01-22 10:12:51 +00:00
* /
2014-10-21 12:04:14 +00:00
upload = { }
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
upload . show = function ( title , files , callback ) {
2014-01-22 10:12:51 +00:00
2015-01-30 23:30:47 +00:00
basicModal . show ( {
body : build . uploadModal ( title , files ) ,
buttons : {
action : {
title : 'Close' ,
class : 'hidden' ,
fn : basicModal . close
}
} ,
callback
2015-07-12 11:19:57 +00:00
} )
2014-07-23 19:23:10 +00:00
2014-10-21 12:04:14 +00:00
}
2014-02-17 15:22:53 +00:00
2014-10-21 12:04:14 +00:00
upload . notify = function ( title , text ) {
2014-02-17 15:22:53 +00:00
2015-07-12 11:19:57 +00:00
if ( text == null || text === '' ) text = 'You can now manage your new photo(s).'
2014-08-16 18:44:11 +00:00
2015-07-12 11:19:57 +00:00
if ( ! window . webkitNotifications ) return false
2014-02-17 15:22:53 +00:00
2015-07-12 11:19:57 +00:00
if ( window . webkitNotifications . checkPermission ( ) !== 0 ) window . webkitNotifications . requestPermission ( )
2014-02-17 15:22:53 +00:00
2015-07-12 11:19:57 +00:00
if ( window . webkitNotifications . checkPermission ( ) === 0 && title ) {
let popup = window . webkitNotifications . createNotification ( '' , title , text )
popup . show ( )
2014-10-21 12:04:14 +00:00
}
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
}
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
upload . start = {
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
local : function ( files ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let albumID = album . getID ( ) ,
error = false ,
warning = false
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
const process = function ( files , file ) {
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
let formData = new FormData ( ) ,
xhr = new XMLHttpRequest ( ) ,
pre _progress = 0 ,
progress = 0
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
const finish = function ( ) {
2014-08-16 18:44:11 +00:00
2015-07-12 11:19:57 +00:00
window . onbeforeunload = null
2014-08-16 18:44:11 +00:00
2015-07-12 11:19:57 +00:00
$ ( '#upload_files' ) . val ( '' )
2014-08-16 18:44:11 +00:00
2015-07-12 11:19:57 +00:00
if ( error === false && warning === false ) {
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
// Success
basicModal . close ( )
upload . notify ( 'Upload complete' )
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
} else if ( error === false && warning === true ) {
2014-08-16 18:44:11 +00:00
2015-07-12 11:19:57 +00:00
// Warning
$ ( '.basicModal #basicModal__action.hidden' ) . show ( )
upload . notify ( 'Upload complete' )
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
} else {
2014-09-19 21:14:53 +00:00
2015-07-12 11:19:57 +00:00
// Error
$ ( '.basicModal #basicModal__action.hidden' ) . show ( )
upload . notify ( 'Upload complete' , 'Failed to upload one or more photos.' )
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
}
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
albums . refresh ( )
2014-07-26 14:31:38 +00:00
2015-07-12 11:19:57 +00:00
if ( album . getID ( ) === false ) lychee . goto ( '0' )
else album . load ( albumID )
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
}
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
// Check if file is supported
if ( file . supported === false ) {
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
// Skip file
2015-07-13 12:29:02 +00:00
if ( file . next != null ) process ( files , file . next )
2015-07-12 11:19:57 +00:00
else {
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
// Look for supported files
// If zero files are supported, hide the upload after a delay
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
let hasSupportedFiles = false
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
for ( let i = 0 ; i < files . length ; i ++ ) {
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
if ( files [ i ] . supported === true ) {
hasSupportedFiles = true
break
}
2014-07-26 14:31:38 +00:00
}
2015-07-12 11:19:57 +00:00
if ( hasSupportedFiles === false ) setTimeout ( finish , 2000 )
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
}
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
return false
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
}
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
formData . append ( 'function' , 'Photo::add' )
formData . append ( 'albumID' , albumID )
formData . append ( 'tags' , '' )
formData . append ( 0 , file )
2014-07-26 14:46:52 +00:00
2015-07-12 11:19:57 +00:00
xhr . open ( 'POST' , api . path )
2014-08-16 17:51:21 +00:00
2015-07-12 11:19:57 +00:00
xhr . onload = function ( ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let wait = false ,
errorText = ''
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
file . ready = true
2014-10-18 15:06:17 +00:00
2015-07-12 11:19:57 +00:00
// Set status
if ( xhr . status === 200 && xhr . responseText === '1' ) {
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
// Success
$ ( '.basicModal .rows .row:nth-child(' + ( file . num + 1 ) + ') .status' )
. html ( 'Finished' )
. addClass ( 'success' )
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
} else {
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
if ( xhr . responseText . substr ( 0 , 6 ) === 'Error:' ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
errorText = xhr . responseText . substr ( 6 ) + ' Please take a look at the console of your browser for further details.'
error = true
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
// Error Status
$ ( '.basicModal .rows .row:nth-child(' + ( file . num + 1 ) + ') .status' )
. html ( 'Failed' )
. addClass ( 'error' )
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
} else if ( xhr . responseText . substr ( 0 , 8 ) === 'Warning:' ) {
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
errorText = xhr . responseText . substr ( 8 )
warning = true
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
// Warning Status
$ ( '.basicModal .rows .row:nth-child(' + ( file . num + 1 ) + ') .status' )
. html ( 'Skipped' )
. addClass ( 'warning' )
2015-06-27 19:03:27 +00:00
2015-07-12 11:19:57 +00:00
} else {
2014-08-16 18:44:11 +00:00
2015-07-12 11:19:57 +00:00
errorText = 'Server returned an unknown response. Please take a look at the console of your browser for further details.'
error = true
2014-08-16 18:18:37 +00:00
2015-07-12 11:19:57 +00:00
// Error Status
$ ( '.basicModal .rows .row:nth-child(' + ( file . num + 1 ) + ') .status' )
. html ( 'Failed' )
. addClass ( 'error' )
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
}
2015-07-12 11:19:57 +00:00
$ ( '.basicModal .rows .row:nth-child(' + ( file . num + 1 ) + ') p.notice' )
. html ( errorText )
. show ( )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
// Throw error
if ( error === true ) lychee . error ( 'Upload failed. Server returned the status code ' + xhr . status + '!' , xhr , xhr . responseText )
}
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
// Check if there are file which are not finished
for ( let i = 0 ; i < files . length ; i ++ ) {
if ( files [ i ] . ready === false ) {
wait = true
break
2014-10-21 12:04:14 +00:00
}
2014-08-16 17:51:21 +00:00
2015-07-12 11:19:57 +00:00
}
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
// Finish upload when all files are finished
if ( wait === false ) finish ( )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
}
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
xhr . upload . onprogress = function ( e ) {
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
if ( e . lengthComputable !== true ) return false
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
// Calculate progress
progress = ( e . loaded / e . total * 100 | 0 )
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
// Set progress when progress has changed
if ( progress > pre _progress ) {
$ ( '.basicModal .rows .row:nth-child(' + ( file . num + 1 ) + ') .status' ) . html ( progress + '%' )
pre _progress = progress
}
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
if ( progress >= 100 ) {
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
// Scroll to the uploading file
let scrollPos = 0
if ( ( file . num + 1 ) > 4 ) scrollPos = ( file . num + 1 - 4 ) * 40
$ ( '.basicModal .rows' ) . scrollTop ( scrollPos )
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
// Set status to processing
$ ( '.basicModal .rows .row:nth-child(' + ( file . num + 1 ) + ') .status' ) . html ( 'Processing' )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
// Upload next file
2015-07-13 12:29:02 +00:00
if ( file . next != null ) process ( files , file . next )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
}
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
}
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
xhr . send ( formData )
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
}
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
if ( files . length <= 0 ) return false
if ( albumID === false || visible . albums ( ) === true ) albumID = 0
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
for ( let i = 0 ; i < files . length ; i ++ ) {
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
files [ i ] . num = i
files [ i ] . ready = false
files [ i ] . supported = true
2014-05-11 22:15:01 +00:00
2015-07-12 11:19:57 +00:00
if ( i < files . length - 1 ) files [ i ] . next = files [ i + 1 ]
else files [ i ] . next = null
2014-05-11 22:15:01 +00:00
2014-10-21 12:04:14 +00:00
// Check if file is supported
2015-07-12 11:19:57 +00:00
if ( files [ i ] . type !== 'image/jpeg' && files [ i ] . type !== 'image/jpg' && files [ i ] . type !== 'image/png' && files [ i ] . type !== 'image/gif' ) {
2014-10-21 12:04:14 +00:00
2015-07-12 11:19:57 +00:00
files [ i ] . ready = true
files [ i ] . supported = false
2014-01-22 10:12:51 +00:00
2014-05-11 22:15:01 +00:00
}
2014-10-21 12:04:14 +00:00
}
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
window . onbeforeunload = function ( ) { return 'Lychee is currently uploading!' }
2014-01-22 10:12:51 +00:00
2015-01-30 23:30:47 +00:00
upload . show ( 'Uploading' , files , function ( ) {
2014-01-22 10:12:51 +00:00
2015-01-30 23:30:47 +00:00
// Upload first file
2015-07-12 11:19:57 +00:00
process ( files , files [ 0 ] )
2015-01-30 23:30:47 +00:00
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
} ,
2014-01-22 10:12:51 +00:00
2015-05-04 20:16:29 +00:00
url : function ( url = '' ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let albumID = album . getID ( )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
url = ( typeof url === 'string' ? url : '' )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
if ( albumID === false ) albumID = 0
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
const action = function ( data ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let files = [ ]
2014-10-21 12:04:14 +00:00
2015-07-12 11:19:57 +00:00
if ( data . link && data . link . length > 3 ) {
2015-01-30 23:30:47 +00:00
2015-07-12 11:19:57 +00:00
basicModal . close ( )
let extension = data . link . split ( '.' ) . pop ( )
if ( extension !== 'jpeg' && extension !== 'jpg' && extension !== 'png' && extension !== 'gif' && extension !== 'webp' ) {
loadingBar . show ( 'error' , 'File format of link not supported.' )
return false
2015-01-09 13:34:38 +00:00
}
2014-05-12 19:40:25 +00:00
2015-01-09 13:34:38 +00:00
files [ 0 ] = {
2015-07-12 11:19:57 +00:00
name : data . link ,
supported : true
2015-01-09 13:34:38 +00:00
}
2014-07-18 15:27:45 +00:00
2015-01-09 13:34:38 +00:00
upload . show ( 'Importing URL' , files , function ( ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
$ ( '.basicModal .rows .row .status' ) . html ( 'Importing' )
2014-09-19 21:14:53 +00:00
2015-07-12 11:19:57 +00:00
let params = {
2015-02-02 20:55:33 +00:00
url : data . link ,
albumID
}
2015-02-02 22:36:33 +00:00
api . post ( 'Import::url' , params , function ( data ) {
2014-01-22 10:12:51 +00:00
2015-06-28 21:13:48 +00:00
// Same code as in import.dropbox()
if ( data !== true ) {
$ ( '.basicModal .rows .row p.notice' )
. html ( 'The import has been finished, but returned warnings or errors. Please take a look at the log (Settings -> Show Log) for further details.' )
2015-07-12 11:19:57 +00:00
. show ( )
2015-06-28 21:13:48 +00:00
$ ( '.basicModal .rows .row .status' )
. html ( 'Finished' )
2015-07-12 11:19:57 +00:00
. addClass ( 'warning' )
2015-06-28 21:13:48 +00:00
// Show close button
2015-07-12 11:19:57 +00:00
$ ( '.basicModal #basicModal__action.hidden' ) . show ( )
2015-06-28 21:13:48 +00:00
// Log error
2015-07-12 11:19:57 +00:00
lychee . error ( null , params , data )
2015-06-28 21:13:48 +00:00
} else {
2015-07-12 11:19:57 +00:00
basicModal . close ( )
2015-06-28 21:13:48 +00:00
}
2015-07-12 11:19:57 +00:00
upload . notify ( 'Import complete' )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
albums . refresh ( )
2015-01-30 23:30:47 +00:00
2015-07-12 11:19:57 +00:00
if ( album . getID ( ) === false ) lychee . goto ( '0' )
else album . load ( albumID )
2015-01-30 23:30:47 +00:00
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
} else basicModal . error ( 'link' )
2014-02-17 15:22:53 +00:00
2015-01-09 13:34:38 +00:00
}
basicModal . show ( {
2015-09-05 21:02:58 +00:00
body : lychee . html ` <p>Please enter the direct link to a photo to import it: <input class='text' name='link' type='text' placeholder='http://' value=' $ ${ url } '></p> ` ,
2015-01-09 13:34:38 +00:00
buttons : {
action : {
title : 'Import' ,
fn : action
} ,
cancel : {
title : 'Cancel' ,
fn : basicModal . close
}
}
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
} ,
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
server : function ( ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let albumID = album . getID ( )
if ( albumID === false ) albumID = 0
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
const action = function ( data ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let files = [ ]
2015-01-22 10:23:16 +00:00
2015-01-09 13:34:38 +00:00
files [ 0 ] = {
2015-07-12 11:19:57 +00:00
name : data . path ,
supported : true
}
2014-05-12 20:13:47 +00:00
2015-01-09 13:34:38 +00:00
upload . show ( 'Importing from server' , files , function ( ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
$ ( '.basicModal .rows .row .status' ) . html ( 'Importing' )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let params = {
2015-02-02 20:55:33 +00:00
albumID ,
path : data . path
}
2015-02-02 22:36:33 +00:00
api . post ( 'Import::server' , params , function ( data ) {
2014-09-19 21:14:53 +00:00
2015-07-12 11:19:57 +00:00
albums . refresh ( )
upload . notify ( 'Import complete' )
2015-01-30 23:30:47 +00:00
2015-07-06 14:54:59 +00:00
if ( data === 'Notice: Import only contained albums!' ) {
// No error, but the folder only contained albums
2014-01-22 10:12:51 +00:00
2015-07-06 14:54:59 +00:00
// Go back to the album overview to show the imported albums
2015-07-12 11:19:57 +00:00
if ( visible . albums ( ) ) lychee . load ( )
else lychee . goto ( '' )
2015-07-06 14:54:59 +00:00
2015-07-12 11:19:57 +00:00
basicModal . close ( )
2015-07-06 14:54:59 +00:00
2015-07-12 11:19:57 +00:00
return true
2015-07-06 14:54:59 +00:00
} else if ( data === 'Warning: Folder empty or no readable files to process!' ) {
// Error because the import could not start
$ ( '.basicModal .rows .row p.notice' )
. html ( 'Folder empty or no readable files to process. Please take a look at the log (Settings -> Show Log) for further details.' )
2015-07-12 11:19:57 +00:00
. show ( )
2015-07-06 14:54:59 +00:00
$ ( '.basicModal .rows .row .status' )
. html ( 'Failed' )
2015-07-12 11:19:57 +00:00
. addClass ( 'error' )
2015-07-06 14:54:59 +00:00
// Log error
2015-07-12 11:19:57 +00:00
lychee . error ( 'Could not start import because the folder was empty!' , params , data )
2015-07-06 14:54:59 +00:00
} else if ( data !== true ) {
// Maybe an error, maybe just some skipped photos
$ ( '.basicModal .rows .row p.notice' )
. html ( 'The import has been finished, but returned warnings or errors. Please take a look at the log (Settings -> Show Log) for further details.' )
2015-07-12 11:19:57 +00:00
. show ( )
2015-07-06 14:54:59 +00:00
$ ( '.basicModal .rows .row .status' )
. html ( 'Finished' )
2015-07-12 11:19:57 +00:00
. addClass ( 'warning' )
2015-07-06 14:54:59 +00:00
// Log error
2015-07-12 11:19:57 +00:00
lychee . error ( null , params , data )
2015-07-06 14:54:59 +00:00
} else {
// No error, everything worked fine
2015-07-12 11:19:57 +00:00
basicModal . close ( )
2015-07-06 14:54:59 +00:00
2015-01-30 23:30:47 +00:00
}
2015-07-06 14:54:59 +00:00
2015-07-12 11:19:57 +00:00
if ( album . getID ( ) === false ) lychee . goto ( '0' )
else album . load ( albumID )
2015-01-30 23:30:47 +00:00
2015-07-06 14:54:59 +00:00
// Show close button
2015-07-12 11:19:57 +00:00
$ ( '.basicModal #basicModal__action.hidden' ) . show ( )
2015-01-30 23:30:47 +00:00
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2015-01-09 13:34:38 +00:00
}
2014-02-17 15:22:53 +00:00
2015-01-09 13:34:38 +00:00
basicModal . show ( {
2015-09-05 21:02:58 +00:00
body : lychee . html ` <p>This action will import all photos, folders and sub-folders which are located in the following directory. The <b>original files will be deleted</b> after the import when possible. <input class='text' name='path' type='text' maxlength='100' placeholder='Absolute path to directory' value=' $ ${ lychee . location } uploads/import/'></p> ` ,
2015-01-09 13:34:38 +00:00
buttons : {
action : {
title : 'Import' ,
fn : action
} ,
cancel : {
title : 'Cancel' ,
fn : basicModal . close
}
}
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
} ,
2014-01-22 10:12:51 +00:00
2014-10-21 12:04:14 +00:00
dropbox : function ( ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let albumID = album . getID ( )
if ( albumID === false ) albumID = 0
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
const success = function ( files ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let links = ''
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
for ( let i = 0 ; i < files . length ; i ++ ) {
2014-05-12 20:13:47 +00:00
2015-07-12 11:19:57 +00:00
links += files [ i ] . link + ','
2014-01-22 10:12:51 +00:00
2015-01-30 23:30:47 +00:00
files [ i ] = {
2015-07-12 11:19:57 +00:00
name : files [ i ] . link ,
supported : true
}
2014-05-12 20:13:47 +00:00
2015-01-30 23:30:47 +00:00
}
2014-01-22 10:12:51 +00:00
2015-01-30 23:30:47 +00:00
// Remove last comma
2015-07-12 11:19:57 +00:00
links = links . substr ( 0 , links . length - 1 )
2014-01-22 10:12:51 +00:00
2015-01-30 23:30:47 +00:00
upload . show ( 'Importing from Dropbox' , files , function ( ) {
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
$ ( '.basicModal .rows .row .status' ) . html ( 'Importing' )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
let params = {
2015-02-02 20:55:33 +00:00
url : links ,
albumID
}
2015-02-02 22:36:33 +00:00
api . post ( 'Import::url' , params , function ( data ) {
2014-09-19 21:14:53 +00:00
2015-06-28 21:13:48 +00:00
// Same code as in import.url()
if ( data !== true ) {
$ ( '.basicModal .rows .row p.notice' )
. html ( 'The import has been finished, but returned warnings or errors. Please take a look at the log (Settings -> Show Log) for further details.' )
2015-07-12 11:19:57 +00:00
. show ( )
2015-06-28 21:13:48 +00:00
$ ( '.basicModal .rows .row .status' )
. html ( 'Finished' )
2015-07-12 11:19:57 +00:00
. addClass ( 'warning' )
2015-06-28 21:13:48 +00:00
// Show close button
2015-07-12 11:19:57 +00:00
$ ( '.basicModal #basicModal__action.hidden' ) . show ( )
2015-06-28 21:13:48 +00:00
// Log error
2015-07-12 11:19:57 +00:00
lychee . error ( null , params , data )
2015-06-28 21:13:48 +00:00
} else {
2015-07-12 11:19:57 +00:00
basicModal . close ( )
2015-06-28 21:13:48 +00:00
}
2015-07-12 11:19:57 +00:00
upload . notify ( 'Import complete' )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
albums . refresh ( )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
if ( album . getID ( ) === false ) lychee . goto ( '0' )
else album . load ( albumID )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
} )
2014-01-22 10:12:51 +00:00
2015-07-12 11:19:57 +00:00
} )
2015-01-30 23:30:47 +00:00
}
2014-01-22 10:12:51 +00:00
2015-01-30 23:30:47 +00:00
lychee . loadDropbox ( function ( ) {
Dropbox . choose ( {
linkType : 'direct' ,
multiselect : true ,
success
2015-07-12 11:19:57 +00:00
} )
} )
2014-01-22 10:12:51 +00:00
}
2014-10-21 12:04:14 +00:00
}