Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public getBgForName = (name: string) => {
- name = name.toLowerCase();
- var instance = this;
- var dir = this.file.dataDirectory;
- return new Promise(function (fulfill, reject) {
- instance.file.checkDir(dir, name).then(() => {
- // directory exists. Is there a bg file?
- dir = dir + '/' + name + '/';
- instance.file.checkFile(dir, 'bg.jpg').then(() => {
- console.log('read file');
- fulfill(dir + '/' + 'bg.jpg')
- }, (err) => {
- // dl file and re-call
- console.log('needs to download file!')
- instance.transfer.create().download(encodeURI('https://host.tld/'+name+'/bg.jpg'), dir + 'bg.jpg', true, {})
- .then((data) => {
- return instance.getBgForName(name).then((url) => {return url});
- }, (err) => {
- console.log(err)
- })
- })
- }, (err) => {
- // create dir and re-call
- instance.file.createDir(dir, name, true).then(() => {
- instance.getBgForName(name).then((url) => {fulfill(url)});
- })
- })
- });
- }
Add Comment
Please, Sign In to add comment