Skip to content

Commit

Permalink
Merge pull request #17 from nekoplanet/typecheck-fix
Browse files Browse the repository at this point in the history
- packages/backend/src/server/api/endpoints/meta.ts
      ์ปค๋ฐ‹ d20542c ์ฐธ๊ณ .
      ์ธ์Šคํ„ด์Šค ๋ฉ”ํƒ€์ •๋ณด ๋ง์•„์ฃผ๋Š” MetaEntityService ๋ผ๋Š”๊ฒŒ ์ถ”๊ฐ€๋˜์–ด, meta ์—”๋“œํฌ์ธํŠธ ํ•ธ๋“ค๋Ÿฌ๊ฐ€ ์–˜๋ฅผ ์‚ฌ์šฉํ•˜๋„๋ก ์ˆ˜์ •
- S3 ์„ค์ • ๊ด€๋ จ
  - packages/backend/src/config.ts
  - packages/backend/src/core/S3Service.ts
  - packages/backend/src/core/entities/MetaEntityService.ts
- ํ…Œ์ŠคํŠธ ์ฝ”๋“œ ํƒ€์ž…์ฒดํฌ ์ˆ˜์ •: packages/backend/test/unit/packages/backend/test/unit
  ์ปค๋ฐ‹ c7d7da8 ์ฐธ๊ณ 
  • Loading branch information
seojangho authored Aug 3, 2024
2 parents 7f639b0 + 41aa26f commit ccb1ae4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 118 deletions.
16 changes: 0 additions & 16 deletions packages/backend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,6 @@ export type Config = {
index: string;
scope?: 'local' | 'global' | string[];
} | undefined;
s3: {
baseUrl: string;
bucket: string;
prefix: string;
endpoint: string;
region?: string;
useSSL: boolean;
accessKey: string;
secretKey: string;
options?: {
setPublicRead?: boolean;
forcePathStyle?: boolean;
useProxy?: boolean;
}
} | undefined;
skebStatus: {
method: string;
endpoint: string;
Expand Down Expand Up @@ -287,7 +272,6 @@ export function loadConfig(): Config {
dbReplications: config.dbReplications,
dbSlaves: config.dbSlaves,
meilisearch: config.meilisearch,
s3: config.s3,
redis,
redisForPubsub: config.redisForPubsub ? convertRedisOptions(config.redisForPubsub, host) : redis,
redisForSystemQueue: config.redisForSystemQueue ? convertRedisOptions(config.redisForSystemQueue, host) : redisForJobQueue,
Expand Down
8 changes: 4 additions & 4 deletions packages/backend/src/core/S3Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { NodeHttpHandler, NodeHttpHandlerOptions } from '@smithy/node-http-handl
import { bindThis } from '@/decorators.js';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import type { Meta } from '@/models/entities/Meta.js';
import type { MiMeta } from '@/models/Meta.js';
import { HttpRequestService } from '@/core/HttpRequestService.js';
import type { DeleteObjectCommandInput, PutObjectCommandInput } from '@aws-sdk/client-s3';

Expand All @@ -28,7 +28,7 @@ export class S3Service {
}

@bindThis
public getS3Client(meta: Meta): S3Client {
public getS3Client(meta: MiMeta): S3Client {
const u = meta.objectStorageEndpoint
? `${meta.objectStorageUseSSL ? 'https' : 'http'}://${meta.objectStorageEndpoint}`
: `${meta.objectStorageUseSSL ? 'https' : 'http'}://example.net`; // dummy url to select http(s) agent
Expand All @@ -55,7 +55,7 @@ export class S3Service {
}

@bindThis
public async upload(meta: Meta, input: PutObjectCommandInput) {
public async upload(meta: MiMeta, input: PutObjectCommandInput) {
const client = this.getS3Client(meta);
return new Upload({
client,
Expand All @@ -67,7 +67,7 @@ export class S3Service {
}

@bindThis
public delete(meta: Meta, input: DeleteObjectCommandInput) {
public delete(meta: MiMeta, input: DeleteObjectCommandInput) {
const client = this.getS3Client(meta);
return client.send(new DeleteObjectCommand(input));
}
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/entities/MetaEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export class MetaEntityService {
reCaptcha: instance.enableRecaptcha,
recaptcha: instance.enableRecaptcha,
turnstile: instance.enableTurnstile,
objectStorage: !!this.config.s3,
objectStorage: instance.useObjectStorage,
serviceWorker: instance.enableServiceWorker,
miauth: true,
},
Expand Down
93 changes: 1 addition & 92 deletions packages/backend/src/server/api/endpoints/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,98 +35,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
private metaEntityService: MetaEntityService,
) {
super(meta, paramDef, async (ps, me) => {
const instance = await this.metaService.fetch(true);

const ads = await this.adsRepository.createQueryBuilder('ads')
.where('ads.expiresAt > :now', { now: new Date() })
.andWhere('ads.startsAt <= :now', { now: new Date() })
.andWhere(new Brackets(qb => {
// ๆ›œๆ—ฅใฎใƒ“ใƒƒใƒˆใƒ•ใƒฉใ‚ฐใ‚’็ขบ่ชใ™ใ‚‹
qb.where('ads.dayOfWeek & :dayOfWeek > 0', { dayOfWeek: 1 << new Date().getDay() })
.orWhere('ads.dayOfWeek = 0');
}))
.getMany();

const response: any = {
maintainerName: instance.maintainerName,
maintainerEmail: instance.maintainerEmail,

version: this.config.version,

name: instance.name,
uri: this.config.url,
description: instance.description,
langs: instance.langs,
tosUrl: instance.termsOfServiceUrl,
repositoryUrl: instance.repositoryUrl,
feedbackUrl: instance.feedbackUrl,
disableRegistration: instance.disableRegistration,
emailRequiredForSignup: instance.emailRequiredForSignup,
enableHcaptcha: instance.enableHcaptcha,
hcaptchaSiteKey: instance.hcaptchaSiteKey,
enableRecaptcha: instance.enableRecaptcha,
recaptchaSiteKey: instance.recaptchaSiteKey,
enableTurnstile: instance.enableTurnstile,
turnstileSiteKey: instance.turnstileSiteKey,
swPublickey: instance.swPublicKey,
themeColor: instance.themeColor,
mascotImageUrl: instance.mascotImageUrl,
bannerUrl: instance.bannerUrl,
infoImageUrl: instance.infoImageUrl,
serverErrorImageUrl: instance.serverErrorImageUrl,
notFoundImageUrl: instance.notFoundImageUrl,
iconUrl: instance.iconUrl,
backgroundImageUrl: instance.backgroundImageUrl,
logoImageUrl: instance.logoImageUrl,
maxNoteTextLength: MAX_NOTE_TEXT_LENGTH,
// ใ‚ฏใƒฉใ‚คใ‚ขใƒณใƒˆใฎๆ‰‹้–“ใ‚’ๆธ›ใ‚‰ใ™ใŸใ‚ใ‚ใ‚‰ใ‹ใ˜ใ‚JSONใซๅค‰ๆ›ใ—ใฆใŠใ
defaultLightTheme: instance.defaultLightTheme ? JSON.stringify(JSON5.parse(instance.defaultLightTheme)) : null,
defaultDarkTheme: instance.defaultDarkTheme ? JSON.stringify(JSON5.parse(instance.defaultDarkTheme)) : null,
ads: ads.map(ad => ({
id: ad.id,
url: ad.url,
place: ad.place,
ratio: ad.ratio,
imageUrl: ad.imageUrl,
dayOfWeek: ad.dayOfWeek,
})),
enableEmail: instance.enableEmail,
enableServiceWorker: instance.enableServiceWorker,

translatorAvailable: instance.deeplAuthKey != null,

serverRules: instance.serverRules,

policies: { ...DEFAULT_POLICIES, ...instance.policies },

mediaProxy: this.config.mediaProxy,

...(ps.detail ? {
cacheRemoteFiles: instance.cacheRemoteFiles,
cacheRemoteSensitiveFiles: instance.cacheRemoteSensitiveFiles,
requireSetup: (await this.usersRepository.countBy({
host: IsNull(),
})) === 0,
} : {}),
};

if (ps.detail) {
const proxyAccount = instance.proxyAccountId ? await this.userEntityService.pack(instance.proxyAccountId).catch(() => null) : null;

response.proxyAccountName = proxyAccount ? proxyAccount.username : null;
response.features = {
registration: !instance.disableRegistration,
emailRequiredForSignup: instance.emailRequiredForSignup,
hcaptcha: instance.enableHcaptcha,
recaptcha: instance.enableRecaptcha,
turnstile: instance.enableTurnstile,
objectStorage: instance.useObjectStorage,
serviceWorker: instance.enableServiceWorker,
miauth: true,
};
}

return response;
return ps.detail ? await this.metaEntityService.packDetailed() : await this.metaEntityService.pack();
});
}
}
3 changes: 3 additions & 0 deletions packages/backend/test/unit/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ describe('NoteCreateService', () => {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: [],
noteEditHistory: [],
};

const poll: IPoll = {
Expand Down
10 changes: 5 additions & 5 deletions packages/backend/test/unit/activitypub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
imageObject,
);
assert.ok(!driveFile.isLink);
assert.ok(driveFile && !driveFile.isLink);

const sensitiveImageObject: IApDocument = {
type: 'Document',
Expand All @@ -312,7 +312,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
sensitiveImageObject,
);
assert.ok(!sensitiveDriveFile.isLink);
assert.ok(sensitiveDriveFile && !sensitiveDriveFile.isLink);
});

test('cacheRemoteFiles=false disables caching', async () => {
Expand All @@ -328,7 +328,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
imageObject,
);
assert.ok(driveFile.isLink);
assert.ok(driveFile && driveFile.isLink);

const sensitiveImageObject: IApDocument = {
type: 'Document',
Expand Down Expand Up @@ -407,7 +407,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
imageObject,
);
assert.ok(!driveFile.isLink);
assert.ok(driveFile && !driveFile.isLink);

const sensitiveImageObject: IApDocument = {
type: 'Document',
Expand Down Expand Up @@ -486,7 +486,7 @@ describe('ActivityPub', () => {
await createRandomRemoteUser(resolver, personService),
imageObject,
);
assert.ok(!driveFile.isLink);
assert.ok(driveFile && !driveFile.isLink);

const sensitiveImageObject: IApDocument = {
type: 'Document',
Expand Down
3 changes: 3 additions & 0 deletions packages/backend/test/unit/misc/is-renote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ const base: MiNote = {
replyUserHost: null,
renoteUserId: null,
renoteUserHost: null,
updatedAt: null,
updatedAtHistory: [],
noteEditHistory: [],
};

describe('misc:is-renote', () => {
Expand Down

0 comments on commit ccb1ae4

Please sign in to comment.