import type { DirCacheService, DirCacheServiceOption } from './types'; export class DirCacheServiceImplement implements DirCacheService { option: DirCacheServiceOption; useId?: string; constructor(option: DirCacheServiceOption) { this.option = option; } init(useId: string): void { this.useId = useId; } unInit(): void { this.useId = undefined; } getRootDir(): string { return this.option.media.getRootDir(); } getUserDir(): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.getRootDir()}/${this.useId}`; } getMessageDir(): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.getRootDir()}/${this.useId}/msg`; } getConversationDir(convId: string): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.getRootDir()}/${this.useId}/msg/${convId}`; } getFileDir(convId: string, file: string): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.getRootDir()}/${this.useId}/msg/${convId}/${file}`; } _getUserDir(): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.useId}`; } _getMessageDir(): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.useId}/msg`; } _getConversationDir(convId: string): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.useId}/msg/${convId}`; } _getFileDir(convId: string, file: string): string { // if (this.useId === undefined) // throw new Error('Initialize the object first.'); return `${this.useId}/msg/${convId}/${file}`; } isExistedUserDir(): Promise { return this.option.media.isExistedDir(this._getUserDir()); } isExistedMessageDir(): Promise { return this.option.media.isExistedDir(this._getMessageDir()); } isExistedConversationDir(convId: string): Promise { return this.option.media.isExistedDir(this._getConversationDir(convId)); } isExistedFile(file: string): Promise { return this.option.media.isExistedFile(file); } createUserDir(): Promise { return this.option.media.createDir(this._getUserDir()); } createMessageDir(): Promise { return this.option.media.createDir(this._getMessageDir()); } createConversationDir(convId: string): Promise { return this.option.media.createDir(this._getConversationDir(convId)); } deleteUserDir(): Promise { return this.option.media.deleteDir(this._getUserDir()); } deleteMessageDir(): Promise { return this.option.media.deleteDir(this._getMessageDir()); } deleteConversationDir(convId: string): Promise { return this.option.media.deleteDir(this._getConversationDir(convId)); } }