Skip to content

Commit

Permalink
[accel-wave] _filename
Browse files Browse the repository at this point in the history
  • Loading branch information
koyopro committed Dec 23, 2024
1 parent fdf9b92 commit d70c529
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions packages/accel-wave/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class BaseUploader extends Config {
attr: string | undefined;
protected hasUpdate: boolean = false;
protected _storage: Storage;
protected _filename: string | undefined;
protected item: Item | undefined;
protected removedItems: Item[] = [];

Expand All @@ -38,25 +39,24 @@ export class BaseUploader extends Config {
}

get filename() {
return this.item?.identifier ?? "";
}
set filename(value: string) {
if (this.item) this.item.identifier = value;
return this._filename ?? "";
}

get file() {
if (this.item?.file) return this.item.file;
if (this.model && this.attr) {
const identifier = (this.model as any)[this.attr];
const path = this.pathFor(identifier);
this.item = new Item(identifier, this._storage.retrive(path));
this._filename = identifier;
this.item = new Item(this.filename, this._storage.retrive(path));
return this.item.file;
}
}

set file(file: File | undefined) {
if (this.item) this.removedItems.push(this.item);
this.item = file ? new Item(file.name, file) : undefined;
this._filename = file?.name;
this.item = file ? new Item(this.filename, file) : undefined;
this.hasUpdate = true;
}

Expand All @@ -73,7 +73,7 @@ export class BaseUploader extends Config {
store(file?: File | undefined | null) {
if (file) this.file = file;
if (file === null) this.file = undefined;
if (this.hasUpdate && this.item?.file && this.filename) {
if (this.hasUpdate && this.item) {
this._storage.store(this.item.file, this.path);
this.hasUpdate = false;
}
Expand All @@ -84,7 +84,7 @@ export class BaseUploader extends Config {
}

protected get path() {
return this.pathFor(this.filename);
return this.pathFor(this.item?.identifier ?? "");
}

protected pathFor(identifier: string) {
Expand Down

0 comments on commit d70c529

Please sign in to comment.