private performCopy()

in src/app/files/files.service.ts [771:804]


    private performCopy(source: ApiFile, destination: ApiFile, name?: string): Promise<ApiFile> {
        let copy = {
            file: source,
            parent: destination,
            name: name ? name : null
        };

        if (source.id == destination.id) {
            return Promise.reject<ApiFile>("Invalid destination.");
        }

        return this._http.post('files/copy', JSON.stringify(copy), null, false)
            .then(progress => {
                return this.monitorProgress(progress)
                    .then(_ => {
                        return this._http.get("/files?id=" + progress.file.id, null, false)
                            .then(f => {
                                this._change.next(FileChangeEvent.created(ApiFile.fromObj(f)));
                                return f;
                            })
                            .catch(e => {
                                if (e.status == 404) {
                                    this._notificationService.warn('Copying "' + copy.file.name.toLowerCase() + '" failed.');
                                    return;
                                }
                                throw e;
                            });
                    })
            })
            .catch(e => {
                this.handleError(e, source.physical_path);
                throw e;
            });
    }