Skip to content

Commit 0b50ced

Browse files
committed
refactor rename request
1 parent 99de835 commit 0b50ced

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/contents.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,25 @@ export class Drive implements Contents.IDrive {
475475
} catch (error) {
476476
// HEAD request failed for this file name, continue, as name doesn't already exist.
477477
} finally {
478-
data = await renameObjects(currentDrive.name, {
478+
const result = await renameObjects(currentDrive.name, {
479479
path: relativePath,
480480
newPath: newRelativePath,
481481
newFileName: newFileName,
482482
registeredFileTypes: this._registeredFileTypes
483483
});
484+
485+
data = {
486+
name: newFileName,
487+
path: PathExt.join(currentDrive.name, result.formattedNewPath!),
488+
last_modified: result.response.data.last_modified,
489+
created: '',
490+
content: PathExt.extname(newFileName) !== '' ? null : [], // TODO: add dir check
491+
format: result.format!,
492+
mimetype: result.mimetype!,
493+
size: result.response.data.size,
494+
writable: true,
495+
type: result.type!
496+
};
484497
}
485498
} else {
486499
// create new element at root would mean modifying a drive

src/requests.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -338,23 +338,18 @@ export async function renameObjects(
338338
options.path,
339339
formattedNewPath
340340
);
341-
data = {
342-
name: options.newFileName,
343-
path: PathExt.join(driveName, formattedNewPath),
344-
last_modified: renamedObject.data.last_modified,
345-
created: '',
346-
content: PathExt.extname(options.newFileName) !== '' ? null : [], // TODO: add dir check
341+
return {
342+
response: renamedObject,
343+
formattedNewPath: formattedNewPath,
347344
format: fileFormat as Contents.FileFormat,
348345
mimetype: fileMimeType,
349-
size: renamedObject.data.size,
350-
writable: true,
351346
type: fileType
352347
};
353348
} catch (error) {
354349
// renaming failed if directory didn't exist and was only part of a path
355350
}
356351

357-
return data;
352+
return {};
358353
}
359354

360355
/**

0 commit comments

Comments
 (0)