mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-25 00:36:42 -06:00
use 'name' param as GridFS file's 'filename'
This commit is contained in:
parent
a7762aea4f
commit
fb422b4d60
6 changed files with 9 additions and 7 deletions
|
@ -144,11 +144,10 @@ export default (
|
|||
}
|
||||
|
||||
// Create DriveFile document
|
||||
const file = await addToGridFS(`${user._id}/${name}`, data, {
|
||||
const file = await addToGridFS(name, data, {
|
||||
user_id: user._id,
|
||||
folder_id: folder !== null ? folder._id : null,
|
||||
type: mime,
|
||||
name: name,
|
||||
comment: comment,
|
||||
properties: properties
|
||||
});
|
||||
|
|
|
@ -24,7 +24,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Issue query
|
||||
const files = await DriveFile
|
||||
.find({
|
||||
'metadata.name': name,
|
||||
filename: name,
|
||||
'metadata.user_id': user._id,
|
||||
'metadata.folder_id': folderId
|
||||
});
|
||||
|
|
|
@ -34,7 +34,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
// Get 'name' parameter
|
||||
const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$;
|
||||
if (nameErr) return rej('invalid name param');
|
||||
if (name) file.metadata.name = name;
|
||||
if (name) file.filename = name;
|
||||
|
||||
// Get 'folder_id' parameter
|
||||
const [folderId, folderIdErr] = $(params.folder_id).optional.nullable.id().$;
|
||||
|
@ -61,7 +61,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
|
|||
|
||||
await DriveFile.update(file._id, {
|
||||
$set: {
|
||||
'metadata.name': file.metadata.name,
|
||||
filename: file.filename,
|
||||
'metadata.folder_id': file.metadata.folder_id
|
||||
}
|
||||
});
|
||||
|
|
|
@ -47,6 +47,7 @@ export default (
|
|||
|
||||
_target.id = _file._id;
|
||||
_target.created_at = _file.uploadDate;
|
||||
_target.name = _file.filename;
|
||||
|
||||
_target = Object.assign(_target, _file.metadata);
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ async function sendFileById(req: express.Request, res: express.Response): Promis
|
|||
const file = await DriveFile.findOne({ _id: fileId });
|
||||
|
||||
// validate name
|
||||
if (req.params.name !== undefined && req.params.name !== file.metadata.name) {
|
||||
if (req.params.name !== undefined && req.params.name !== file.filename) {
|
||||
res.status(404).send('there is no file has given name');
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -21,15 +21,17 @@ const migrateToGridFS = async (doc) => {
|
|||
const id = doc._id
|
||||
const buffer = doc.data.buffer
|
||||
const created_at = doc.created_at
|
||||
const name = doc.name
|
||||
|
||||
delete doc._id
|
||||
delete doc.created_at
|
||||
delete doc.datasize
|
||||
delete doc.hash
|
||||
delete doc.data
|
||||
delete doc.name
|
||||
|
||||
const bucket = await getGridFSBucket()
|
||||
const added = await writeToGridFS(bucket, buffer, id, `${id}/${doc.name}`, { metadata: doc })
|
||||
const added = await writeToGridFS(bucket, buffer, id, name, { metadata: doc })
|
||||
|
||||
const result = await DriveFile.update(id, {
|
||||
$set: {
|
||||
|
|
Loading…
Reference in a new issue