Support SVG (#3883)
* Update add-file.ts * Update package.json * Revert "Update add-file.ts" This reverts commit ba0fe83b54a44493447208dfb3cc304a60df6fdd. * Update add-file.ts * Update package.json * Update add-file.ts * Update add-file.ts * Create image.svg * Update api.ts
This commit is contained in:
parent
00d5fdfc13
commit
018837db0b
@ -43,6 +43,7 @@
|
|||||||
"@types/gulp-uglify": "3.0.6",
|
"@types/gulp-uglify": "3.0.6",
|
||||||
"@types/gulp-util": "3.0.34",
|
"@types/gulp-util": "3.0.34",
|
||||||
"@types/is-root": "1.0.0",
|
"@types/is-root": "1.0.0",
|
||||||
|
"@types/is-svg": "3.0.0",
|
||||||
"@types/is-url": "1.2.28",
|
"@types/is-url": "1.2.28",
|
||||||
"@types/js-yaml": "3.11.4",
|
"@types/js-yaml": "3.11.4",
|
||||||
"@types/katex": "0.5.0",
|
"@types/katex": "0.5.0",
|
||||||
@ -136,6 +137,7 @@
|
|||||||
"http-signature": "1.2.0",
|
"http-signature": "1.2.0",
|
||||||
"insert-text-at-cursor": "0.1.1",
|
"insert-text-at-cursor": "0.1.1",
|
||||||
"is-root": "2.0.0",
|
"is-root": "2.0.0",
|
||||||
|
"is-svg": "3.0.0",
|
||||||
"is-url": "1.2.4",
|
"is-url": "1.2.4",
|
||||||
"js-yaml": "3.12.0",
|
"js-yaml": "3.12.0",
|
||||||
"jsdom": "13.1.0",
|
"jsdom": "13.1.0",
|
||||||
|
@ -4,10 +4,11 @@ import * as fs from 'fs';
|
|||||||
import * as mongodb from 'mongodb';
|
import * as mongodb from 'mongodb';
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
import * as debug from 'debug';
|
import * as debug from 'debug';
|
||||||
import fileType = require('file-type');
|
|
||||||
import * as Minio from 'minio';
|
import * as Minio from 'minio';
|
||||||
import * as uuid from 'uuid';
|
import * as uuid from 'uuid';
|
||||||
import * as sharp from 'sharp';
|
import * as sharp from 'sharp';
|
||||||
|
import * as fileType from 'file-type';
|
||||||
|
import * as isSvg from 'is-svg';
|
||||||
|
|
||||||
import DriveFile, { IMetadata, getDriveFileBucket, IDriveFile } from '../../models/drive-file';
|
import DriveFile, { IMetadata, getDriveFileBucket, IDriveFile } from '../../models/drive-file';
|
||||||
import DriveFolder from '../../models/drive-folder';
|
import DriveFolder from '../../models/drive-folder';
|
||||||
@ -320,6 +321,8 @@ export default async function(
|
|||||||
const type = fileType(buffer);
|
const type = fileType(buffer);
|
||||||
if (type) {
|
if (type) {
|
||||||
res([type.mime, type.ext]);
|
res([type.mime, type.ext]);
|
||||||
|
} else if (isSvg(buffer)) {
|
||||||
|
res(['image/svg+xml', 'svg'])
|
||||||
} else {
|
} else {
|
||||||
// 種類が同定できなかったら application/octet-stream にする
|
// 種類が同定できなかったら application/octet-stream にする
|
||||||
res(['application/octet-stream', null]);
|
res(['application/octet-stream', null]);
|
||||||
|
14
test/api.ts
14
test/api.ts
@ -808,6 +808,20 @@ describe('API', () => {
|
|||||||
|
|
||||||
expect(res).have.status(400);
|
expect(res).have.status(400);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
it('SVGファイルを作成できる', async(async () => {
|
||||||
|
const izumi = await signup({ username: 'izumi' });
|
||||||
|
|
||||||
|
const res = await assert.request(server)
|
||||||
|
.post('/drive/files/create')
|
||||||
|
.field('i', izumi.token)
|
||||||
|
.attach('file', fs.readFileSync(__dirname + '/resources/image.svg'), 'image.svg');
|
||||||
|
|
||||||
|
expect(res).have.status(200);
|
||||||
|
expect(res.body).be.a('object');
|
||||||
|
expect(res.body).have.property('name').eql('image.svg');
|
||||||
|
expect(res.body).have.property('type').eql('image/svg+xml');
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('drive/files/update', () => {
|
describe('drive/files/update', () => {
|
||||||
|
BIN
test/resources/image.svg
Normal file
BIN
test/resources/image.svg
Normal file
Binary file not shown.
After Width: | Height: | Size: 505 B |
Loading…
Reference in New Issue
Block a user