Skip to content

Commit

Permalink
Merge tag '10.102.626-m544' into custom/atsuchan
Browse files Browse the repository at this point in the history
10.102.626-m544
  • Loading branch information
atsu1125 committed Jan 8, 2023
2 parents 0ec8b2d + 99ed838 commit 91c5b72
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 7 deletions.
1 change: 1 addition & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ common:
image: "Image"
video: "Video"
audio: "Audio"
application: "Application"
desktop-mode: 'Desktop mode'
mobile-mode: 'Mobile mode'
empty: 'Empty'
Expand Down
1 change: 1 addition & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ common:
image: "画像"
video: "動画"
audio: "音声"
application: "アプリケーション"
desktop-mode: 'デスクトップ版'
mobile-mode: 'モバイル版'
empty: 'ありません!'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "misskey",
"author": "mei23 <[email protected]>",
"version": "10.102.625-m544",
"version": "10.102.626-m544",
"codename": "m544",
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/client/app/admin/views/drive.vue
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<option value="image/*">{{ $t('@.image') }}</option>
<option value="video/*">{{ $t('@.video') }}</option>
<option value="audio/*">{{ $t('@.audio') }}</option>
<option value="application/*">{{ $t('@.application') }}</option>
</ui-select>
</ui-horizon-group>
<div class="kidvdlkg" v-for="file in files" :key="file.id">
Expand Down
10 changes: 10 additions & 0 deletions src/misc/mime-type-filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import escapeRegExp = require('escape-regexp');

export const typeFilterValidater = /^([*]|[a-z]+)[/]([*]|[0-9A-Za-z+.-]+)$/;

export function genTypeFilterRegex(pattern: string) {
const m = pattern.match(typeFilterValidater);
if (!m) throw 'Invalid pattern';
const cnv = (x: string) => x === '*' ? '[^/]+' : escapeRegExp(x);
return new RegExp(`^${cnv(m[1])}[/]${cnv(m[2])}$`);
}
5 changes: 3 additions & 2 deletions src/server/api/endpoints/admin/drive/files.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import $ from 'cafy';
import { toDbHost } from '../../../../../misc/convert-host';
import { genTypeFilterRegex, typeFilterValidater } from '../../../../../misc/mime-type-filter';
import File, { packMany } from '../../../../../models/drive-file';
import { getSystem1 } from '../../../../../services/emoji-store';
import define from '../../../define';
Expand Down Expand Up @@ -45,7 +46,7 @@ export const meta = {
},

type: {
validator: $.optional.str.match(/^[a-zA-Z\/\-\*]+$/)
validator: $.optional.str.match(typeFilterValidater)
},
}
};
Expand Down Expand Up @@ -93,7 +94,7 @@ export default define(meta, async (ps, me) => {
}

if (ps.type) {
q.contentType = new RegExp(`^${ps.type.replace(/\*/g, '.+?')}$`);
q.contentType = genTypeFilterRegex(ps.type);
}

const files = await File
Expand Down
5 changes: 3 additions & 2 deletions src/server/api/endpoints/drive/files.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id';
import { genTypeFilterRegex, typeFilterValidater } from '../../../../misc/mime-type-filter';
import DriveFile, { packMany } from '../../../../models/drive-file';
import define from '../../define';

Expand Down Expand Up @@ -46,7 +47,7 @@ export const meta = {
},

type: {
validator: $.optional.str.match(/^[a-zA-Z\/\-\*]+$/)
validator: $.optional.str.match(typeFilterValidater)
}
},

Expand Down Expand Up @@ -102,7 +103,7 @@ export default define(meta, async (ps, user) => {
}

if (ps.type) {
query.contentType = new RegExp(`^${ps.type.replace(/\*/g, '.+?')}$`);
query.contentType = genTypeFilterRegex(ps.type);
}

const files = await DriveFile
Expand Down
5 changes: 3 additions & 2 deletions src/server/api/endpoints/drive/stream.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import $ from 'cafy';
import ID, { transform } from '../../../../misc/cafy-id';
import { genTypeFilterRegex, typeFilterValidater } from '../../../../misc/mime-type-filter';
import DriveFile, { packMany } from '../../../../models/drive-file';
import define from '../../define';

Expand Down Expand Up @@ -27,7 +28,7 @@ export const meta = {
},

type: {
validator: $.optional.str.match(/^[a-zA-Z\/\-\*]+$/)
validator: $.optional.str.match(typeFilterValidater)
}
},

Expand Down Expand Up @@ -61,7 +62,7 @@ export default define(meta, async (ps, user) => {
}

if (ps.type) {
query.contentType = new RegExp(`^${ps.type.replace(/\*/g, '.+?')}$`);
query.contentType = genTypeFilterRegex(ps.type);
}

const files = await DriveFile
Expand Down
87 changes: 87 additions & 0 deletions test/mime-type-filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import * as assert from 'assert';
import { genTypeFilterRegex, typeFilterValidater } from '../src/misc/mime-type-filter';

describe('typeFilterValidater', () => {
it('Allow image/jpeg', () => {
assert.strictEqual(typeFilterValidater.test('image/jpeg'), true);
});

it('Allow image/*', () => {
assert.strictEqual(typeFilterValidater.test('image/*'), true);
});

it('Allow */*', () => {
assert.strictEqual(typeFilterValidater.test('*/*'), true);
});

it('Reject image/a*', () => {
assert.strictEqual(typeFilterValidater.test('image/a*'), false);
});

it('Reject image/a*b*c', () => {
assert.strictEqual(typeFilterValidater.test('image/a*b*c'), false);
});

it('Reject image*/jpeg', () => {
assert.strictEqual(typeFilterValidater.test('image*/jpeg'), false);
});

it('Reject */*/*', () => {
assert.strictEqual(typeFilterValidater.test('*/*/*'), false);
});

it('Allow video/mp4', () => {
assert.strictEqual(typeFilterValidater.test('video/mp4'), true);
});

it('Allow video/MP1S', () => {
assert.strictEqual(typeFilterValidater.test('video/MP1S'), true);
});

it('Allow image/x-icon', () => {
assert.strictEqual(typeFilterValidater.test('image/x-icon'), true);
});

it('Allow image/svg+xml', () => {
assert.strictEqual(typeFilterValidater.test('image/svg+xml'), true);
});

it('Allow audio/vnd.wave', () => {
assert.strictEqual(typeFilterValidater.test('audio/vnd.wave'), true);
});

it('Reject %', () => {
assert.strictEqual(typeFilterValidater.test('image/%'), false);
});

it('Reject _', () => {
assert.strictEqual(typeFilterValidater.test('image/_'), false);
});

it('Reject .*', () => {
assert.strictEqual(typeFilterValidater.test('image/.*'), false);
});

// 難しいのでエスケープで対応する
//it('Reject .+', () => {
// assert.strictEqual(typeFilterValidater.test('image/.+'), false);
//});
});

describe('genTypeFilterRegex', () => {
it('image/jpeg', () => {
assert.strictEqual(genTypeFilterRegex('image/jpeg').source, '^image[/]jpeg$');
});

it('image/*', () => {
assert.strictEqual(genTypeFilterRegex('image/*').source, '^image[/][^/]+$');
});

it('*/*', () => {
assert.strictEqual(genTypeFilterRegex('*/*').source, '^[^/]+[/][^/]+$');
});

it('image/.+', () => {
assert.strictEqual(genTypeFilterRegex('image/.+').source, '^image[/]\\.\\+$');
});
});

0 comments on commit 91c5b72

Please sign in to comment.