mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 23:40:13 +01:00
parent
21c09c67e4
commit
26e1c1dc4a
5 changed files with 71 additions and 2 deletions
|
|
@ -114,6 +114,13 @@ class FileStoreStrategy {
|
|||
unlink() {
|
||||
}
|
||||
|
||||
/** rename the file (physical)
|
||||
* @li at database the filename is updated after this method
|
||||
* @param newFilePath the new file path
|
||||
*/
|
||||
rename(newFilePath) {
|
||||
}
|
||||
|
||||
/** return the storage name
|
||||
* @return the storage name
|
||||
*/
|
||||
|
|
@ -287,6 +294,14 @@ export class FileStoreStrategyFilesystem extends FileStoreStrategy {
|
|||
fs.unlink(filePath, () => {});
|
||||
}
|
||||
|
||||
/** rename the file (physical)
|
||||
* @li at database the filename is updated after this method
|
||||
* @param newFilePath the new file path
|
||||
*/
|
||||
rename(newFilePath) {
|
||||
fs.renameSync(this.fileObj.versions[this.versionName].path, newFilePath);
|
||||
}
|
||||
|
||||
/** return the storage name
|
||||
* @return the storage name
|
||||
*/
|
||||
|
|
@ -389,3 +404,16 @@ export const copyFile = function(fileObj, newCardId, fileStoreStrategyFactory) {
|
|||
|
||||
readStream.pipe(writeStream);
|
||||
};
|
||||
|
||||
export const rename = function(fileObj, newName, fileStoreStrategyFactory) {
|
||||
Object.keys(fileObj.versions).forEach(versionName => {
|
||||
const strategy = fileStoreStrategyFactory.getFileStrategy(fileObj, versionName);
|
||||
const newFilePath = strategy.getNewPath(fileStoreStrategyFactory.storagePath, newName);
|
||||
strategy.rename(newFilePath);
|
||||
|
||||
Attachments.update({ _id: fileObj._id }, { $set: {
|
||||
"name": newName,
|
||||
[`versions.${versionName}.path`]: newFilePath,
|
||||
} });
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue