Skip to content

Commit 91d9ff7

Browse files
committed
refactor save request
1 parent 2050abd commit 91d9ff7

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

src/contents.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,26 @@ export class Drive implements Contents.IDrive {
532532
): Promise<Contents.IModel> {
533533
if (localPath !== '') {
534534
const currentDrive = extractCurrentDrive(localPath, this._drivesList);
535+
const currentPath = formatPath(localPath);
535536

536-
data = await saveObject(currentDrive.name, {
537-
path: formatPath(localPath),
537+
const result = await saveObject(currentDrive.name, {
538+
path: currentPath,
538539
param: options,
539540
registeredFileTypes: this._registeredFileTypes
540541
});
542+
543+
data = {
544+
name: currentPath,
545+
path: PathExt.join(currentDrive.name, currentPath),
546+
last_modified: result.response.last_modified,
547+
created: result.response.last_modified,
548+
content: result.response.content,
549+
format: result.fileFormat,
550+
mimetype: result.fileMimeType,
551+
size: result.response.data.size,
552+
writable: true,
553+
type: result.fileType
554+
};
541555
} else {
542556
// create new element at root would mean modifying a drive
543557
console.warn('Operation not supported.');

src/requests.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -219,19 +219,12 @@ export async function saveObject(
219219
}
220220
);
221221

222-
data = {
223-
name: PathExt.basename(options.path),
224-
path: PathExt.join(driveName, options.path),
225-
last_modified: response.data.last_modified,
226-
created: response.data.last_modified,
227-
content: response.data.content,
228-
format: fileFormat as Contents.FileFormat,
229-
mimetype: fileMimeType,
230-
size: response.data.size,
231-
writable: true,
232-
type: fileType
222+
return {
223+
response: response,
224+
fileType: fileType,
225+
fileMimeType: fileMimeType,
226+
fileFormat: fileFormat as Contents.FileFormat
233227
};
234-
return data;
235228
}
236229

237230
/**

0 commit comments

Comments
 (0)