build: affine Node.js server charts (#2895)

This commit is contained in:
LongYinan
2023-06-29 22:02:46 +08:00
committed by GitHub
parent d7fcad2d0d
commit 8021efd81a
43 changed files with 1112 additions and 124 deletions
+8 -1
View File
@@ -8,7 +8,14 @@ export const S3_SERVICE = Symbol('S3_SERVICE');
export const S3: FactoryProvider<S3Client> = {
provide: S3_SERVICE,
useFactory: (config: Config) => {
const s3 = new S3Client(config.objectStorage.config);
const s3 = new S3Client({
region: 'auto',
endpoint: `https://${config.objectStorage.r2.accountId}.r2.cloudflarestorage.com`,
credentials: {
accessKeyId: config.objectStorage.r2.accessKeyId,
secretAccessKey: config.objectStorage.r2.secretAccessKey,
},
});
return s3;
},
inject: [Config],
@@ -15,11 +15,11 @@ export class StorageService {
) {}
async uploadFile(key: string, file: FileUpload) {
if (this.config.objectStorage.enable) {
if (this.config.objectStorage.r2.enabled) {
await this.s3.send(
new PutObjectCommand({
Body: file.createReadStream(),
Bucket: this.config.objectStorage.config.bucket,
Bucket: this.config.objectStorage.r2.bucket,
Key: key,
})
);
@@ -1,10 +1,19 @@
import { Storage } from '@affine/storage';
import { Controller, Get, NotFoundException, Param, Res } from '@nestjs/common';
import type { Storage } from '@affine/storage';
import {
Controller,
Get,
Inject,
NotFoundException,
Param,
Res,
} from '@nestjs/common';
import type { Response } from 'express';
import { StorageProvide } from '../../storage';
@Controller('/api/workspaces')
export class WorkspacesController {
constructor(private readonly storage: Storage) {}
constructor(@Inject(StorageProvide) private readonly storage: Storage) {}
@Get('/:id/blobs/:name')
async blob(
@@ -1,5 +1,5 @@
import { Storage } from '@affine/storage';
import { ForbiddenException, NotFoundException } from '@nestjs/common';
import type { Storage } from '@affine/storage';
import { ForbiddenException, Inject, NotFoundException } from '@nestjs/common';
import {
Args,
Field,
@@ -21,6 +21,7 @@ import type { User, Workspace } from '@prisma/client';
import GraphQLUpload from 'graphql-upload/GraphQLUpload.mjs';
import { PrismaService } from '../../prisma';
import { StorageProvide } from '../../storage';
import type { FileUpload } from '../../types';
import { Auth, CurrentUser } from '../auth';
import { UserType } from '../users/resolver';
@@ -60,7 +61,7 @@ export class WorkspaceResolver {
constructor(
private readonly prisma: PrismaService,
private readonly permissionProvider: PermissionService,
private readonly storage: Storage
@Inject(StorageProvide) private readonly storage: Storage
) {}
@ResolveField(() => Permission, {