mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 17:03:49 +01:00
This commit is contained in:
parent
823a3d765e
commit
934debd68e
@ -13,13 +13,13 @@ import { Duplex } from 'stream';
|
||||
|
||||
const log = debug('misskey:register-drive-file');
|
||||
|
||||
const addToGridFS = (name, binary, metadata): Promise<any> => new Promise(async (resolve, reject) => {
|
||||
const addToGridFS = (name, binary, type, metadata): Promise<any> => new Promise(async (resolve, reject) => {
|
||||
const dataStream = new Duplex();
|
||||
dataStream.push(binary);
|
||||
dataStream.push(null);
|
||||
|
||||
const bucket = await getGridFSBucket();
|
||||
const writeStream = bucket.openUploadStream(name, { metadata });
|
||||
const writeStream = bucket.openUploadStream(name, { contentType: type, metadata });
|
||||
writeStream.once('finish', (doc) => { resolve(doc); });
|
||||
writeStream.on('error', reject);
|
||||
dataStream.pipe(writeStream);
|
||||
@ -144,10 +144,9 @@ export default (
|
||||
}
|
||||
|
||||
// Create DriveFile document
|
||||
const file = await addToGridFS(name, data, {
|
||||
const file = await addToGridFS(name, data, mime, {
|
||||
user_id: user._id,
|
||||
folder_id: folder !== null ? folder._id : null,
|
||||
type: mime,
|
||||
comment: comment,
|
||||
properties: properties
|
||||
});
|
||||
|
@ -48,6 +48,7 @@ export default (
|
||||
_target.id = _file._id;
|
||||
_target.created_at = _file.uploadDate;
|
||||
_target.name = _file.filename;
|
||||
_target.type = _file.contentType;
|
||||
|
||||
_target = Object.assign(_target, _file.metadata);
|
||||
|
||||
|
44
tools/migration/issue_882.js
Normal file
44
tools/migration/issue_882.js
Normal file
@ -0,0 +1,44 @@
|
||||
// for Node.js interpret
|
||||
|
||||
const { default: DriveFile } = require('../../built/api/models/drive-file')
|
||||
|
||||
const migrate = async (doc) => {
|
||||
const result = await DriveFile.update(doc._id, {
|
||||
$set: {
|
||||
contentType: doc.metadata.type
|
||||
},
|
||||
$unset: {
|
||||
'metadata.type': ''
|
||||
}
|
||||
})
|
||||
return result.ok === 1
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let i = 0;
|
||||
|
||||
const count = await db.get('drive_files').count({});
|
||||
|
||||
const iterate = async () => {
|
||||
if (i == count) return true;
|
||||
console.log(`${i} / ${count}`);
|
||||
const doc = (await db.get('drive_files').find({}, { limit: 1, skip: i }))[0]
|
||||
const res = await migrate(doc);
|
||||
if (!res) {
|
||||
return false;
|
||||
} else {
|
||||
i++
|
||||
return await iterate();
|
||||
}
|
||||
}
|
||||
|
||||
const res = await iterate();
|
||||
|
||||
if (res) {
|
||||
return 'ok';
|
||||
} else {
|
||||
throw 'something happened';
|
||||
}
|
||||
}
|
||||
|
||||
main().then(console.dir).catch(console.error)
|
@ -22,6 +22,7 @@ const migrateToGridFS = async (doc) => {
|
||||
const buffer = doc.data ? doc.data.buffer : Buffer.from([0x00]) // アップロードのバグなのか知らないけどなぜか data が存在しない drive_file ドキュメントがまれにあることがわかったので
|
||||
const created_at = doc.created_at
|
||||
const name = doc.name
|
||||
const type = doc.type
|
||||
|
||||
delete doc._id
|
||||
delete doc.created_at
|
||||
@ -29,9 +30,10 @@ const migrateToGridFS = async (doc) => {
|
||||
delete doc.hash
|
||||
delete doc.data
|
||||
delete doc.name
|
||||
delete doc.type
|
||||
|
||||
const bucket = await getGridFSBucket()
|
||||
const added = await writeToGridFS(bucket, buffer, id, name, { metadata: doc })
|
||||
const added = await writeToGridFS(bucket, buffer, id, name, { contentType: type, metadata: doc })
|
||||
|
||||
const result = await DriveFile.update(id, {
|
||||
$set: {
|
||||
|
Loading…
Reference in New Issue
Block a user