-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(buckets): fix abstract interfaces, adjust bucket to inherit abst…
…ract bucket
- Loading branch information
Showing
10 changed files
with
118 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,18 @@ | ||
// Remote file management | ||
import { FileSystemErrors } from '../../errors/Errors' | ||
import { Fil } from '../../Fil' | ||
import { RFMInterface } from '../interface/RFM.interface' | ||
import { FileSystemExport } from '~/libraries/Files/types/filesystem' | ||
|
||
export abstract class RFM implements RFMInterface { | ||
export abstract class RFM { | ||
constructor() { | ||
if (this.constructor.name === 'RFM') | ||
throw new Error(FileSystemErrors.RFM_ABSTRACT_ONLY) | ||
} | ||
|
||
updateIndex(index: FileSystemExport): void { | ||
throw new Error(FileSystemErrors.METHOD_MISSING) | ||
} | ||
abstract updateIndex(index: FileSystemExport): void | ||
|
||
get index(): FileSystemExport | null { | ||
throw new Error(FileSystemErrors.METHOD_MISSING) | ||
} | ||
abstract get index(): FileSystemExport | undefined | ||
|
||
delete(file: Fil): boolean { | ||
throw new Error(FileSystemErrors.METHOD_MISSING) | ||
} | ||
abstract pullFile(id: string, name: string, size: number): void | ||
|
||
upload(file: File, name: string, meta: any): string { | ||
throw new Error(FileSystemErrors.METHOD_MISSING) | ||
} | ||
abstract removeFile(name: string): void | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { BucketAbstract } from '../abstracts/Bucket.abstract' | ||
import { Config } from '~/config' | ||
import { | ||
FileSystemExport, | ||
FILESYSTEM_TYPE, | ||
} from '~/libraries/Files/types/filesystem' | ||
|
||
export class PrivateBucket extends BucketAbstract { | ||
private _index?: FileSystemExport | ||
/** | ||
* @getter | ||
* @returns file system export data | ||
*/ | ||
get index(): FileSystemExport | undefined { | ||
return this._index | ||
} | ||
|
||
/** | ||
* @method init | ||
* @description Initializes bucket | ||
* @param name bucket name | ||
* @returns {Promise<FileSystemExport>} a promise that resolves when the initialization completes | ||
*/ | ||
async init({ | ||
name, | ||
encrypted, | ||
}: { | ||
name: string | ||
encrypted: boolean | ||
}): Promise<FileSystemExport> { | ||
await this.getBucket({ name, encrypted }) | ||
if (!this._buckets || !this._key) { | ||
throw new Error('woah') | ||
} | ||
try { | ||
const data = [] | ||
for await (const bytes of this._buckets.pullPath( | ||
this._key, | ||
Config.textile.fsTable, | ||
)) { | ||
data.push(bytes) | ||
} | ||
this._index = JSON.parse( | ||
await new Blob(data, { | ||
type: 'application/json', | ||
}).text(), | ||
) | ||
|
||
if (!this._index) throw new Error('Index not found') | ||
|
||
return this._index | ||
} catch (e) { | ||
return { | ||
type: FILESYSTEM_TYPE.DEFAULT, | ||
version: 1, | ||
content: [], | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @method updateIndex | ||
* @param index FileSystemExport | ||
* @description sets file system import data | ||
*/ | ||
async updateIndex(index: FileSystemExport) { | ||
if (!this._buckets || !this._key) { | ||
throw new Error('Bucket or bucket key not found') | ||
} | ||
this._index = index | ||
const res = await this._buckets.pushPath( | ||
this._key, | ||
Config.textile.fsTable, | ||
Buffer.from(JSON.stringify(index)), | ||
{ root: this._root }, | ||
) | ||
this._root = res.root | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters