Merge tag '2023.9.0' into merge-upstream

This commit is contained in:
riku6460
2023-09-25 12:43:07 +09:00
1235 changed files with 19016 additions and 13835 deletions

View File

@@ -193,7 +193,7 @@ function nothingToDo<T, V = T>(value: T): V {
export class MemoryKVCache<T, V = T> {
public cache: Map<string, { date: number; value: V; }>;
private lifetime: number;
private gcIntervalHandle: NodeJS.Timer;
private gcIntervalHandle: NodeJS.Timeout;
private toMapConverter: (value: T) => V;
private fromMapConverter: (cached: V) => T | undefined;

View File

@@ -5,8 +5,8 @@
import { AhoCorasick } from 'slacc';
import RE2 from 're2';
import type { MiNote } from '@/models/entities/Note.js';
import type { MiUser } from '@/models/entities/User.js';
import type { MiNote } from '@/models/Note.js';
import type { MiUser } from '@/models/User.js';
type NoteLike = {
userId: MiNote['userId'];

View File

@@ -3,18 +3,56 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
// 与えられた拡張子とファイル名が一致しているかどうかを確認し、
// 一致していない場合は拡張子を付与して返す
/**
* Array.includes()よりSet.has()の方が高速
*/
const targetExtsToSkip = new Set([
'.gz',
'.tar',
'.tgz',
'.bz2',
'.xz',
'.zip',
'.7z',
]);
const extRegExp = /\.[0-9a-zA-Z]+$/i;
/**
* 与えられた拡張子とファイル名が一致しているかどうかを確認し、
* 一致していない場合は拡張子を付与して返す
*
* extはfile-typeのextを想定
*/
export function correctFilename(filename: string, ext: string | null) {
const dotExt = ext ? ext.startsWith('.') ? ext : `.${ext}` : '.unknown';
if (filename.endsWith(dotExt)) {
return filename;
}
if (ext === 'jpg' && filename.endsWith('.jpeg')) {
return filename;
}
if (ext === 'tif' && filename.endsWith('.tiff')) {
const dotExt = ext ? ext[0] === '.' ? ext : `.${ext}` : '.unknown';
const match = extRegExp.exec(filename);
if (!match || !match[0]) {
// filenameが拡張子を持っていない場合は拡張子をつける
return `${filename}${dotExt}`;
}
const filenameExt = match[0].toLowerCase();
if (
// 未知のファイル形式かつ拡張子がある場合は何もしない
ext === null ||
// 拡張子が一致している場合は何もしない
filenameExt === dotExt ||
// jpeg, tiffを同一視
dotExt === '.jpg' && filenameExt === '.jpeg' ||
dotExt === '.tif' && filenameExt === '.tiff' ||
// dllもexeもportable executableなので判定が正しく行われない
dotExt === '.exe' && filenameExt === '.dll' ||
// 圧縮形式っぽければ下手に拡張子を変えない
// https://github.com/misskey-dev/misskey/issues/11482
targetExtsToSkip.has(dotExt)
) {
return filename;
}
// 拡張子があるが一致していないなどの場合は拡張子を付け足す
return `${filename}${dotExt}`;
}

View File

@@ -5,4 +5,5 @@
import { secureRndstr } from '@/misc/secure-rndstr.js';
// eslint-disable-next-line import/no-default-export
export default () => secureRndstr(16);

View File

@@ -3,6 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
// eslint-disable-next-line import/no-default-export
export default function(reaction: string): string {
switch (reaction) {
case 'like': return '👍';

View File

@@ -0,0 +1,44 @@
/*
* SPDX-FileCopyrightText: syuilo and other misskey contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/
// AIDX
// 長さ8の[2000年1月1日からの経過ミリ秒をbase36でエンコードしたもの] + 長さ4の[個体ID] + 長さ4の[カウンタ]
// (c) mei23
// https://misskey.m544.net/notes/71899acdcc9859ec5708ac24
import { customAlphabet } from 'nanoid';
export const aidxRegExp = /^[0-9a-z]{16}$/;
const TIME2000 = 946684800000;
const TIME_LENGTH = 8;
const NODE_LENGTH = 4;
const NOISE_LENGTH = 4;
const nodeId = customAlphabet('0123456789abcdefghijklmnopqrstuvwxyz', NODE_LENGTH)();
let counter = 0;
function getTime(time: number): string {
time = time - TIME2000;
if (time < 0) time = 0;
return time.toString(36).padStart(TIME_LENGTH, '0').slice(-TIME_LENGTH);
}
function getNoise(): string {
return counter.toString(36).padStart(NOISE_LENGTH, '0').slice(-NOISE_LENGTH);
}
export function genAidx(date: Date): string {
const t = date.getTime();
if (isNaN(t)) throw new Error('Failed to create AIDX: Invalid Date');
counter++;
return getTime(t) + nodeId + getNoise();
}
export function parseAidx(id: string): { date: Date; } {
const time = parseInt(id.slice(0, TIME_LENGTH), 36) + TIME2000;
return { date: new Date(time) };
}

View File

@@ -3,4 +3,5 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
// eslint-disable-next-line import/no-default-export
export default (token: string) => token.length === 16;

View File

@@ -3,8 +3,9 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import type { MiNote } from '@/models/entities/Note.js';
import type { MiNote } from '@/models/Note.js';
// eslint-disable-next-line import/no-default-export
export default function(note: MiNote): boolean {
return note.renoteId != null && (note.text != null || note.hasPoll || (note.fileIds != null && note.fileIds.length > 0));
}

View File

@@ -20,9 +20,8 @@ import { packedChannelSchema } from '@/models/json-schema/channel.js';
import { packedClipSchema } from '@/models/json-schema/clip.js';
import { packedDriveFileSchema } from '@/models/json-schema/drive-file.js';
import { packedDriveFolderSchema } from '@/models/json-schema/drive-folder.js';
import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from '@/models/json-schema/emoji.js';
import { packedFederationInstanceSchema } from '@/models/json-schema/federation-instance.js';
import { packedFlashLikeSchema, packedFlashSchema } from '@/models/json-schema/flash.js';
import { packedFlashLikeSchema } from '@/models/json-schema/flash.js';
import { packedFollowRequestSchema, packedFollowingSchema } from '@/models/json-schema/following.js';
import { packedGalleryLikeSchema, packedGalleryPostSchema } from '@/models/json-schema/gallery.js';
import { packedHashtagSchema } from '@/models/json-schema/hashtag.js';
@@ -35,6 +34,8 @@ import { packedNoteSchema } from '@/models/json-schema/note.js';
import { packedNotificationSchema } from '@/models/json-schema/notification.js';
import { packedPageLikeSchema, packedPageSchema } from '@/models/json-schema/page.js';
import { packedQueueCountSchema } from '@/models/json-schema/queue.js';
import { packedEmojiDetailedSchema, packedEmojiSimpleSchema } from '@/models/json-schema/emoji.js';
import { packedFlashSchema } from '@/models/json-schema/flash.js';
import { packedRenoteMutingSchema } from '@/models/json-schema/renote-muting.js';
import { packedRoleSchema } from '@/models/json-schema/role.js';
import { packedUserListSchema } from '@/models/json-schema/user-list.js';