Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

버그수정+ 타입체크 맞도록 수정 #17

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading