import { LoggingService } from './logging-service' ; import { StoredFile } from './stored-file' ; import { IDropboxEntry } from './idropbox-entry' ; import { Settings } from './settings' ; import { Injectable } from '@angular/core' ; import { IDropboxAuth } from './idropbox-auth' ; import { DropboxBase } from './dropbox-base' ; import { HttpClient } from '@angular/common/http' ; @ Injectable ( ) export class DropboxFileService extends DropboxBase { constructor ( http , settings , loggingService ) { super ( http , settings , loggingService ) ; } download ( entry , auth , byRevision ? ) { return new Promise < StoredFile > ( ( resolve , reject ) => { const isText = entry . name . endsWith ( '.txt' ) ; this . downloadFile ( byRevision ? 'rev:' + entry . rev : entry . id , isText , auth ) . subscribe ( ( value ) => resolve ( new StoredFile ( entry . name , value ) ) , ( error ) => reject ( error ) ) ; } ) ; } delete ( entry , auth ) { return new Promise < any > ( ( resolve , reject ) => { this . doRequest ( 'https://api.dropboxapi.com/2/files/delete' , auth , { path : this . settings . getRemotePath ( entry . name ) } ) . subscribe ( ( ) => resolve ( ) , err => reject ( err ) ) ; } ) ; } upload ( file , auth ) { const fileName = file . fileName ; return new Promise < any > ( ( resolve , reject ) => { this . uploadFile ( this . settings . getRemotePath ( fileName ) , file . contents , auth ) . subscribe ( ( ) => resolve ( ) , err => reject ( err ) ) ; } ) ; } }