summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAcid Chicken (硫酸鶏) <root@acid-chicken.com>2019-01-13 18:21:10 +0900
committersyuilo <Syuilotan@yahoo.co.jp>2019-01-13 18:21:10 +0900
commit018837db0b9f25eeb554f49185d33e9c3969688f (patch)
tree0188b836c80492f9e3f2d551816259d9153c896d
parentMerge branch 'develop' of https://github.com/syuilo/misskey into develop (diff)
downloadmisskey-018837db0b9f25eeb554f49185d33e9c3969688f.tar.gz
misskey-018837db0b9f25eeb554f49185d33e9c3969688f.tar.bz2
misskey-018837db0b9f25eeb554f49185d33e9c3969688f.zip
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
-rw-r--r--package.json2
-rw-r--r--src/services/drive/add-file.ts5
-rw-r--r--test/api.ts14
-rw-r--r--test/resources/image.svg1
4 files changed, 21 insertions, 1 deletions
diff --git a/package.json b/package.json
index d0023df5ae..d3486d9fee 100644
--- a/package.json
+++ b/package.json
@@ -43,6 +43,7 @@
"@types/gulp-uglify": "3.0.6",
"@types/gulp-util": "3.0.34",
"@types/is-root": "1.0.0",
+ "@types/is-svg": "3.0.0",
"@types/is-url": "1.2.28",
"@types/js-yaml": "3.11.4",
"@types/katex": "0.5.0",
@@ -136,6 +137,7 @@
"http-signature": "1.2.0",
"insert-text-at-cursor": "0.1.1",
"is-root": "2.0.0",
+ "is-svg": "3.0.0",
"is-url": "1.2.4",
"js-yaml": "3.12.0",
"jsdom": "13.1.0",
diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts
index 2ea8cdc3bd..38b150a639 100644
--- a/src/services/drive/add-file.ts
+++ b/src/services/drive/add-file.ts
@@ -4,10 +4,11 @@ import * as fs from 'fs';
import * as mongodb from 'mongodb';
import * as crypto from 'crypto';
import * as debug from 'debug';
-import fileType = require('file-type');
import * as Minio from 'minio';
import * as uuid from 'uuid';
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 DriveFolder from '../../models/drive-folder';
@@ -320,6 +321,8 @@ export default async function(
const type = fileType(buffer);
if (type) {
res([type.mime, type.ext]);
+ } else if (isSvg(buffer)) {
+ res(['image/svg+xml', 'svg'])
} else {
// 種類が同定できなかったら application/octet-stream にする
res(['application/octet-stream', null]);
diff --git a/test/api.ts b/test/api.ts
index a7142641d2..d82014e754 100644
--- a/test/api.ts
+++ b/test/api.ts
@@ -808,6 +808,20 @@ describe('API', () => {
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', () => {
diff --git a/test/resources/image.svg b/test/resources/image.svg
new file mode 100644
index 0000000000..1e2bf5b5bb
--- /dev/null
+++ b/test/resources/image.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256"><path fill="#FF40A4" d="M128 80c-16 4-20 24-20 48v16c0 8-8 16-20.3 8 4.3 20 24.3 28 40.3 24s20-24 20-48v-16c0-8 8-16 20.3-8C164 84 144 76 128 80"/><path fill="#FFBF40" d="M192 80c-16 4-20 24-20 48v16c0 8-8 16-20.3 8 4.3 20 24.3 28 40.3 24s20-24 20-48v-16c0-8 8-16 20.3-8C228 84 208 76 192 80"/><path fill="#408EFF" d="M64 80c-16 4-20 24-20 48v16c0 8-8 16-20.3 8C28 172 48 180 64 176s20-24 20-48v-16c0-8 8-16 20.3-8C100 84 80 76 64 80"/></svg>