fix for lint

This commit is contained in:
syuilo 2021-11-13 19:10:14 +09:00
parent 01afdc410e
commit 8b7f5be878
12 changed files with 581 additions and 574 deletions

View file

@ -82,8 +82,7 @@ export default class Reversi {
//#endregion
// ゲームが始まった時点で片方の色の石しかないか、始まった時点で勝敗が決定するようなマップの場合がある
if (!this.canPutSomewhere(BLACK))
this.turn = this.canPutSomewhere(WHITE) ? WHITE : null;
if (!this.canPutSomewhere(BLACK)) this.turn = this.canPutSomewhere(WHITE) ? WHITE : null;
}
/**
@ -226,11 +225,12 @@ export default class Reversi {
// 座標が指し示す位置がボード外に出たとき
if (this.opts.loopedBoard && this.transformXyToPos(
(x = ((x % this.mapWidth) + this.mapWidth) % this.mapWidth),
(y = ((y % this.mapHeight) + this.mapHeight) % this.mapHeight)) === initPos)
(y = ((y % this.mapHeight) + this.mapHeight) % this.mapHeight)) === initPos) {
// 盤面の境界でループし、自分が石を置く位置に戻ってきたとき、挟めるようにしている (ref: Test4のマップ)
return found;
else if (x === -1 || y === -1 || x === this.mapWidth || y === this.mapHeight)
} else if (x === -1 || y === -1 || x === this.mapWidth || y === this.mapHeight) {
return []; // 挟めないことが確定 (盤面外に到達)
}
const pos = this.transformXyToPos(x, y);
if (this.mapDataGet(pos) === 'null') return []; // 挟めないことが確定 (配置不可能なマスに到達)

View file

@ -54,7 +54,7 @@ export async function populateEmoji(emojiName: string, noteUserHost: string | nu
const queryOrNull = async () => (await Emojis.findOne({
name,
host
host,
})) || null;
const emoji = await cache.fetch(`${name} ${host}`, queryOrNull);
@ -111,12 +111,12 @@ export async function prefetchEmojis(emojis: { name: string; host: string | null
for (const host of hosts) {
emojisQuery.push({
name: In(notCachedEmojis.filter(e => e.host === host).map(e => e.name)),
host: host
host: host,
});
}
const _emojis = emojisQuery.length > 0 ? await Emojis.find({
where: emojisQuery,
select: ['name', 'host', 'url']
select: ['name', 'host', 'url'],
}) : [];
for (const emoji of _emojis) {
cache.set(`${emoji.name} ${emoji.host}`, emoji);

View file

@ -1,3 +1,4 @@
/* eslint-disable key-spacing */
import { emojiRegex } from './emoji-regex';
import { fetchMeta } from './fetch-meta';
import { Emojis } from '@/models/index';

View file

@ -66,7 +66,7 @@ function signToRequest(request: Request, key: PrivateKey, includeHeaders: string
const signatureHeader = `keyId="${key.keyId}",algorithm="rsa-sha256",headers="${includeHeaders.join(' ')}",signature="${signature}"`;
request.headers = objectAssignWithLcKey(request.headers, {
Signature: signatureHeader
Signature: signatureHeader,
});
return {

File diff suppressed because it is too large Load diff

View file

@ -163,7 +163,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
uri: person.id,
tags,
isBot,
isCat: (person as any).isCat === true
isCat: (person as any).isCat === true,
})) as IRemoteUser;
await transactionalEntityManager.save(new UserProfile({
@ -173,14 +173,14 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
fields,
birthday: bday ? bday[0] : null,
location: person['vcard:Address'] || null,
userHost: host
userHost: host,
}));
if (person.publicKey) {
await transactionalEntityManager.save(new UserPublickey({
userId: user.id,
keyId: person.publicKey.id,
keyPem: person.publicKey.publicKeyPem
keyPem: person.publicKey.publicKeyPem,
}));
}
});
@ -189,7 +189,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
if (isDuplicateKeyValueError(e)) {
// /users/@a => /users/:id のように入力がaliasなときにエラーになることがあるのを対応
const u = await Users.findOne({
uri: person.id
uri: person.id,
});
if (u) {
@ -218,11 +218,11 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
//#region アバターとヘッダー画像をフェッチ
const [avatar, banner] = await Promise.all([
person.icon,
person.image
person.image,
].map(img =>
img == null
? Promise.resolve(null)
: resolveImage(user!, img).catch(() => null)
: resolveImage(user!, img).catch(() => null),
));
const avatarId = avatar ? avatar.id : null;
@ -258,7 +258,7 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<Us
const emojiNames = emojis.map(emoji => emoji.name);
await Users.update(user!.id, {
emojis: emojiNames
emojis: emojiNames,
});
//#endregion
@ -301,11 +301,11 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
// アバターとヘッダー画像をフェッチ
const [avatar, banner] = await Promise.all([
person.icon,
person.image
person.image,
].map(img =>
img == null
? Promise.resolve(null)
: resolveImage(exist, img).catch(() => null)
: resolveImage(exist, img).catch(() => null),
));
// カスタム絵文字取得
@ -355,7 +355,7 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
if (person.publicKey) {
await UserPublickeys.update({ userId: exist.id }, {
keyId: person.publicKey.id,
keyPem: person.publicKey.publicKeyPem
keyPem: person.publicKey.publicKeyPem,
});
}
@ -372,9 +372,9 @@ export async function updatePerson(uri: string, resolver?: Resolver | null, hint
// 該当ユーザーが既にフォロワーになっていた場合はFollowingもアップデートする
await Followings.update({
followerId: exist.id
followerId: exist.id,
}, {
followerSharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined)
followerSharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined),
});
await updateFeatured(exist.id).catch(err => logger.error(err));
@ -411,8 +411,9 @@ const services: {
};
const $discord = (id: string, name: string) => {
if (typeof name !== 'string')
if (typeof name !== 'string') {
name = 'unknown#0000';
}
const [username, discriminator] = name.split('#');
return { id, username, discriminator };
};
@ -420,14 +421,16 @@ const $discord = (id: string, name: string) => {
function addService(target: { [x: string]: any }, source: IApPropertyValue) {
const service = services[source.name];
if (typeof source.value !== 'string')
if (typeof source.value !== 'string') {
source.value = 'unknown';
}
const [id, username] = source.value.split('@');
if (service)
if (service) {
target[source.name.split(':')[2]] = service(id, username);
}
}
export function analyzeAttachments(attachments: IObject | IObject[] | undefined) {
const fields: {
@ -443,7 +446,7 @@ export function analyzeAttachments(attachments: IObject | IObject[] | undefined)
} else {
fields.push({
name: attachment.name,
value: fromHtml(attachment.value)
value: fromHtml(attachment.value),
});
}
}
@ -487,7 +490,7 @@ export async function updateFeatured(userId: User['id']) {
id: genId(new Date(Date.now() + td)),
createdAt: new Date(),
userId: user.id,
noteId: note!.id
noteId: note!.id,
});
}
});

View file

@ -6,7 +6,7 @@ const ECC_PRELUDE = Buffer.from([0x04]);
const NULL_BYTE = Buffer.from([0]);
const PEM_PRELUDE = Buffer.from(
'3059301306072a8648ce3d020106082a8648ce3d030107034200',
'hex'
'hex',
);
// Android Safetynet attestations are signed with this cert:
@ -134,7 +134,7 @@ export function verifyLogin({
const verificationData = Buffer.concat(
[authenticatorData, hash(clientDataJSON)],
32 + authenticatorData.length
32 + authenticatorData.length,
);
return crypto
@ -158,14 +158,14 @@ export const procedures = {
const publicKeyU2F = Buffer.concat(
[ECC_PRELUDE, negTwo, negThree],
1 + 32 + 32
1 + 32 + 32,
);
return {
publicKey: publicKeyU2F,
valid: true
valid: true,
};
}
},
},
'android-key': {
verify({
@ -174,7 +174,7 @@ export const procedures = {
clientDataHash,
publicKey,
rpIdHash,
credentialId
credentialId,
}: {
attStmt: any,
authenticatorData: Buffer,
@ -189,7 +189,7 @@ export const procedures = {
const verificationData = Buffer.concat([
authenticatorData,
clientDataHash
clientDataHash,
]);
const attCert: Buffer = attStmt.x5c[0];
@ -206,7 +206,7 @@ export const procedures = {
const publicKeyData = Buffer.concat(
[ECC_PRELUDE, negTwo, negThree],
1 + 32 + 32
1 + 32 + 32,
);
if (!attCert.equals(publicKeyData)) {
@ -222,9 +222,9 @@ export const procedures = {
return {
valid: isValid,
publicKey: publicKeyData
publicKey: publicKeyData,
};
}
},
},
// what a stupid attestation
'android-safetynet': {
@ -234,7 +234,7 @@ export const procedures = {
clientDataHash,
publicKey,
rpIdHash,
credentialId
credentialId,
}: {
attStmt: any,
authenticatorData: Buffer,
@ -244,14 +244,14 @@ export const procedures = {
credentialId: Buffer,
}) {
const verificationData = hash(
Buffer.concat([authenticatorData, clientDataHash])
Buffer.concat([authenticatorData, clientDataHash]),
);
const jwsParts = attStmt.response.toString('utf-8').split('.');
const header = JSON.parse(base64URLDecode(jwsParts[0]).toString('utf-8'));
const response = JSON.parse(
base64URLDecode(jwsParts[1]).toString('utf-8')
base64URLDecode(jwsParts[1]).toString('utf-8'),
);
const signature = jwsParts[2];
@ -273,7 +273,7 @@ export const procedures = {
const signatureBase = Buffer.from(
jwsParts[0] + '.' + jwsParts[1],
'utf-8'
'utf-8',
);
const valid = crypto
@ -293,13 +293,13 @@ export const procedures = {
const publicKeyData = Buffer.concat(
[ECC_PRELUDE, negTwo, negThree],
1 + 32 + 32
1 + 32 + 32,
);
return {
valid,
publicKey: publicKeyData
publicKey: publicKeyData,
};
}
},
},
packed: {
verify({
@ -308,7 +308,7 @@ export const procedures = {
clientDataHash,
publicKey,
rpIdHash,
credentialId
credentialId,
}: {
attStmt: any,
authenticatorData: Buffer,
@ -319,7 +319,7 @@ export const procedures = {
}) {
const verificationData = Buffer.concat([
authenticatorData,
clientDataHash
clientDataHash,
]);
if (attStmt.x5c) {
@ -342,12 +342,12 @@ export const procedures = {
const publicKeyData = Buffer.concat(
[ECC_PRELUDE, negTwo, negThree],
1 + 32 + 32
1 + 32 + 32,
);
return {
valid: validSignature,
publicKey: publicKeyData
publicKey: publicKeyData,
};
} else if (attStmt.ecdaaKeyId) {
// https://fidoalliance.org/specs/fido-v2.0-id-20180227/fido-ecdaa-algorithm-v2.0-id-20180227.html#ecdaa-verify-operation
@ -357,7 +357,7 @@ export const procedures = {
throw new Error('self attestation is not supported');
}
}
},
},
'fido-u2f': {
@ -367,7 +367,7 @@ export const procedures = {
clientDataHash,
publicKey,
rpIdHash,
credentialId
credentialId,
}: {
attStmt: any,
authenticatorData: Buffer,
@ -397,7 +397,7 @@ export const procedures = {
const publicKeyU2F = Buffer.concat(
[ECC_PRELUDE, negTwo, negThree],
1 + 32 + 32
1 + 32 + 32,
);
const verificationData = Buffer.concat([
@ -405,7 +405,7 @@ export const procedures = {
rpIdHash,
clientDataHash,
credentialId,
publicKeyU2F
publicKeyU2F,
]);
const validSignature = crypto
@ -415,8 +415,8 @@ export const procedures = {
return {
valid: validSignature,
publicKey: publicKeyU2F
publicKey: publicKeyU2F,
};
}
}
},
},
};

View file

@ -244,8 +244,9 @@ export default define(meta, async (ps, user) => {
if (ps.poll) {
if (typeof ps.poll.expiresAt === 'number') {
if (ps.poll.expiresAt < Date.now())
if (ps.poll.expiresAt < Date.now()) {
throw new ApiError(meta.errors.cannotCreateAlreadyExpiredPoll);
}
} else if (typeof ps.poll.expiredAfter === 'number') {
ps.poll.expiresAt = Date.now() + ps.poll.expiredAfter;
}

View file

@ -112,8 +112,9 @@ export default define(meta, async (ps, user) => {
if (exist.length) {
if (poll.multiple) {
if (exist.some(x => x.choice == ps.choice))
if (exist.some(x => x.choice == ps.choice)) {
throw new ApiError(meta.errors.alreadyVoted);
}
} else {
throw new ApiError(meta.errors.alreadyVoted);
}

View file

@ -42,7 +42,7 @@ router.get('/disconnect/github', async ctx => {
const user = await Users.findOneOrFail({
host: null,
token: userToken
token: userToken,
});
const profile = await UserProfiles.findOneOrFail(user.id);
@ -58,7 +58,7 @@ router.get('/disconnect/github', async ctx => {
// Publish i updated event
publishMainStream(user.id, 'meUpdated', await Users.pack(user, user, {
detail: true,
includeSecrets: true
includeSecrets: true,
}));
});
@ -209,12 +209,13 @@ router.get('/gh/cb', async ctx => {
code,
{ redirect_uri },
(err, accessToken, refresh, result) => {
if (err)
if (err) {
rej(err);
else if (result.error)
} else if (result.error) {
rej(result.error);
else
} else {
res({ accessToken });
}
}));
const { login, id } = await getJson('https://api.github.com/user', 'application/vnd.github.v3+json', 10 * 1000, {

View file

@ -41,7 +41,7 @@ router.get('/.well-known/host-meta', async ctx => {
ctx.set('Content-Type', xrd);
ctx.body = XRD({ element: 'Link', attributes: {
type: xrd,
template: `${config.url}${webFingerPath}?resource={uri}`
template: `${config.url}${webFingerPath}?resource={uri}`,
} });
});
@ -51,8 +51,8 @@ router.get('/.well-known/host-meta.json', async ctx => {
links: [{
rel: 'lrdd',
type: jrd,
template: `${config.url}${webFingerPath}?resource={uri}`
}]
template: `${config.url}${webFingerPath}?resource={uri}`,
}],
};
});