fix lint (automattic)

This commit is contained in:
otofune 2017-11-06 16:32:01 +09:00
parent 04648db1c2
commit d5cc4cc9c2
9 changed files with 48 additions and 49 deletions

View File

@ -14,16 +14,16 @@ import { Duplex } from 'stream';
const log = debug('misskey:register-drive-file');
const addToGridFS = (name, binary, metadata): Promise<any> => new Promise(async (resolve, reject) => {
const dataStream = new Duplex()
dataStream.push(binary)
dataStream.push(null)
const dataStream = new Duplex();
dataStream.push(binary);
dataStream.push(null);
const bucket = await getGridFSBucket()
const writeStream = bucket.openUploadStream(name, { metadata })
writeStream.once('finish', (doc) => { resolve(doc) })
writeStream.on('error', reject)
dataStream.pipe(writeStream)
})
const bucket = await getGridFSBucket();
const writeStream = bucket.openUploadStream(name, { metadata });
writeStream.once('finish', (doc) => { resolve(doc); });
writeStream.on('error', reject);
dataStream.pipe(writeStream);
});
/**
* Add file to drive

View File

@ -63,5 +63,5 @@ module.exports = async (params, user, app) => {
// Serialize
const _files = await Promise.all(files.map(file => serialize(file)));
return _files
return _files;
};

View File

@ -33,5 +33,5 @@ module.exports = async (params, user) => {
detail: true
});
return _file
return _file;
};

View File

@ -20,7 +20,6 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
const [fileId, fileIdErr] = $(params.file_id).id().$;
if (fileIdErr) return rej('invalid file_id param');
// Fetch file
const file = await DriveFile
.findOne({
@ -32,7 +31,7 @@ module.exports = (params, user) => new Promise(async (res, rej) => {
return rej('file-not-found');
}
const updateQuery: any = {}
const updateQuery: any = {};
// Get 'name' parameter
const [name, nameErr] = $(params.name).optional.string().pipe(validateFileName).$;

View File

@ -92,6 +92,6 @@ module.exports = async (params, user, app) => {
});
// Serialize
const _timeline = await Promise.all(timeline.map(post => serialize(post, user)))
return _timeline
const _timeline = await Promise.all(timeline.map(post => serialize(post, user)));
return _timeline;
};

View File

@ -8,14 +8,14 @@ const collection = monkDb.get('drive_files.files');
export default collection as any; // fuck type definition
const getGridFSBucket = async (): Promise<mongodb.GridFSBucket> => {
const db = await nativeDbConn()
const db = await nativeDbConn();
const bucket = new mongodb.GridFSBucket(db, {
bucketName: 'drive_files'
})
return bucket
}
});
return bucket;
};
export { getGridFSBucket }
export { getGridFSBucket };
export function validateFileName(name: string): boolean {
return (

View File

@ -40,13 +40,13 @@ export default (
_file = deepcopy(file);
}
if (!_file) return reject('invalid file arg.')
if (!_file) return reject('invalid file arg.');
// rendered target
let _target: any = {};
_target.id = _file._id;
_target.created_at = _file.uploadDate
_target.created_at = _file.uploadDate;
_target = Object.assign(_target, _file.metadata);

View File

@ -16,7 +16,7 @@ export default db;
/**
* MongoDB native module (officialy)
*/
import * as mongodb from 'mongodb'
import * as mongodb from 'mongodb';
let mdb: mongodb.Db;
@ -25,14 +25,14 @@ const nativeDbConn = async (): Promise<mongodb.Db> => {
const db = await ((): Promise<mongodb.Db> => new Promise((resolve, reject) => {
mongodb.MongoClient.connect(uri, (e, db) => {
if (e) return reject(e)
resolve(db)
})
}))()
if (e) return reject(e);
resolve(db);
});
}))();
mdb = db
mdb = db;
return db
}
return db;
};
export { nativeDbConn }
export { nativeDbConn };

View File

@ -97,7 +97,7 @@ app.get('/:id', async (req, res) => {
return;
}
const fileId = new mongodb.ObjectID(req.params.id)
const fileId = new mongodb.ObjectID(req.params.id);
const file = await DriveFile.findOne({ _id: fileId });
if (file == null) {
@ -105,18 +105,18 @@ app.get('/:id', async (req, res) => {
return;
}
const bucket = await getGridFSBucket()
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 => {
const chunks = [];
const readableStream = bucket.openDownloadStream(id);
readableStream.on('data', chunk => {
chunks.push(chunk);
})
});
readableStream.on('end', () => {
resolve(Buffer.concat(chunks))
})
}))(fileId)
resolve(Buffer.concat(chunks));
});
}))(fileId);
send(buffer, file.metadata.type, req, res);
});
@ -128,7 +128,7 @@ app.get('/:id/:name', async (req, res) => {
return;
}
const fileId = new mongodb.ObjectID(req.params.id)
const fileId = new mongodb.ObjectID(req.params.id);
const file = await DriveFile.findOne({ _id: fileId });
if (file == null) {
@ -136,18 +136,18 @@ app.get('/:id/:name', async (req, res) => {
return;
}
const bucket = await getGridFSBucket()
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 => {
const chunks = [];
const readableStream = bucket.openDownloadStream(id);
readableStream.on('data', chunk => {
chunks.push(chunk);
})
});
readableStream.on('end', () => {
resolve(Buffer.concat(chunks))
})
}))(fileId)
resolve(Buffer.concat(chunks));
});
}))(fileId);
send(buffer, file.metadata.type, req, res);
});