Guest User

Untitled

a guest
Jan 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. public getBgForName = (name: string) => {
  2. name = name.toLowerCase();
  3. var instance = this;
  4. var dir = this.file.dataDirectory;
  5. return new Promise(function (fulfill, reject) {
  6. instance.file.checkDir(dir, name).then(() => {
  7. // directory exists. Is there a bg file?
  8. dir = dir + '/' + name + '/';
  9. instance.file.checkFile(dir, 'bg.jpg').then(() => {
  10. console.log('read file');
  11. fulfill(dir + '/' + 'bg.jpg')
  12. }, (err) => {
  13. // dl file and re-call
  14. console.log('needs to download file!')
  15. instance.transfer.create().download(encodeURI('https://host.tld/'+name+'/bg.jpg'), dir + 'bg.jpg', true, {})
  16. .then((data) => {
  17. return instance.getBgForName(name).then((url) => {return url});
  18. }, (err) => {
  19. console.log(err)
  20. })
  21. })
  22. }, (err) => {
  23. // create dir and re-call
  24. instance.file.createDir(dir, name, true).then(() => {
  25. instance.getBgForName(name).then((url) => {fulfill(url)});
  26. })
  27. })
  28.  
  29. });
  30. }
Add Comment
Please, Sign In to add comment