mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-04 02:49:57 +08:00
chore(server): remove octobase storage usage (#5594)
since all blobs have been successfully migrated to r2, the octobase blob functions are no longer necessary.
This commit is contained in:
@@ -1,7 +1,4 @@
|
|||||||
import { Readable } from 'node:stream';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
import type { Storage } from '@affine/storage';
|
|
||||||
import { Injectable, OnModuleInit } from '@nestjs/common';
|
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
BlobInputType,
|
BlobInputType,
|
||||||
@@ -12,20 +9,13 @@ import {
|
|||||||
Config,
|
Config,
|
||||||
createStorageProvider,
|
createStorageProvider,
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
OctoBaseStorageModule,
|
|
||||||
OnEvent,
|
OnEvent,
|
||||||
toBuffer,
|
|
||||||
} from '../../../fundamentals';
|
} from '../../../fundamentals';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class WorkspaceBlobStorage implements OnModuleInit {
|
export class WorkspaceBlobStorage {
|
||||||
public readonly provider: StorageProvider;
|
public readonly provider: StorageProvider;
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated for backwards compatibility, need to be removed in next stable release
|
|
||||||
*/
|
|
||||||
private octobase: Storage | null = null;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly event: EventEmitter,
|
private readonly event: EventEmitter,
|
||||||
private readonly config: Config
|
private readonly config: Config
|
||||||
@@ -33,42 +23,12 @@ export class WorkspaceBlobStorage implements OnModuleInit {
|
|||||||
this.provider = createStorageProvider(this.config.storage, 'blob');
|
this.provider = createStorageProvider(this.config.storage, 'blob');
|
||||||
}
|
}
|
||||||
|
|
||||||
async onModuleInit() {
|
|
||||||
if (!this.config.node.test) {
|
|
||||||
this.octobase = await OctoBaseStorageModule.Storage.connect(
|
|
||||||
this.config.db.url
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async put(workspaceId: string, key: string, blob: BlobInputType) {
|
async put(workspaceId: string, key: string, blob: BlobInputType) {
|
||||||
const buf = await toBuffer(blob);
|
await this.provider.put(`${workspaceId}/${key}`, blob);
|
||||||
await this.provider.put(`${workspaceId}/${key}`, buf);
|
|
||||||
if (this.octobase) {
|
|
||||||
await this.octobase.uploadBlob(workspaceId, buf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(workspaceId: string, key: string) {
|
async get(workspaceId: string, key: string) {
|
||||||
const result = await this.provider.get(`${workspaceId}/${key}`);
|
return this.provider.get(`${workspaceId}/${key}`);
|
||||||
if (!result.body && this.octobase) {
|
|
||||||
const blob = await this.octobase.getBlob(workspaceId, key);
|
|
||||||
|
|
||||||
if (!blob) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
body: Readable.from(blob.data),
|
|
||||||
metadata: {
|
|
||||||
contentType: blob.contentType,
|
|
||||||
contentLength: blob.size,
|
|
||||||
lastModified: new Date(blob.lastModified),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async list(workspaceId: string) {
|
async list(workspaceId: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user