summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorotofune <otofune@gmail.com>2017-11-06 15:35:20 +0900
committerotofune <otofune@gmail.com>2017-11-06 15:35:20 +0900
commita5160a1bbaa3dd75d7ef45b305a90020317e95a8 (patch)
tree7a1879eb302b8c8df9c9214c6d8a4f1904361737 /src
parentserializers - drive-file: add created_at field by uploadedDate (diff)
downloadmisskey-a5160a1bbaa3dd75d7ef45b305a90020317e95a8.tar.gz
misskey-a5160a1bbaa3dd75d7ef45b305a90020317e95a8.tar.bz2
misskey-a5160a1bbaa3dd75d7ef45b305a90020317e95a8.zip
fileserver - support DriveFile w/ GridFS
Diffstat (limited to 'src')
-rw-r--r--src/file/server.ts23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/file/server.ts b/src/file/server.ts
index ee67cf7860..bd29e13c5c 100644
--- a/src/file/server.ts
+++ b/src/file/server.ts
@@ -9,7 +9,7 @@ import * as cors from 'cors';
import * as mongodb from 'mongodb';
import * as gm from 'gm';
-import File from '../api/models/drive-file';
+import DriveFile, { getGridFSBucket } from '../api/models/drive-file';
/**
* Init app
@@ -97,17 +97,28 @@ app.get('/:id', async (req, res) => {
return;
}
- const file = await File.findOne({ _id: new mongodb.ObjectID(req.params.id) });
+ const fileId = new mongodb.ObjectID(req.params.id)
+ const file = await DriveFile.findOne({ _id: fileId });
if (file == null) {
res.status(404).sendFile(`${__dirname} / assets / dummy.png`);
return;
- } else if (file.data == null) {
- res.sendStatus(400);
- return;
}
- send(file.data.buffer, file.type, req, res);
+ const bucket = await getGridFSBucket()
+
+ const buffer = await ((id): Promise<Buffer> => new Promise((resolve, reject) => {
+ const chunks = []
+ const readableStream = bucket.openDownloadStream(id)
+ readableStream.on('data', chunk => {
+ chunks.push(chunk);
+ })
+ readableStream.on('end', () => {
+ resolve(Buffer.concat(chunks))
+ })
+ }))(fileId)
+
+ send(buffer, file.metadata.type, req, res);
});
app.get('/:id/:name', async (req, res) => {