fix(core): update
This commit is contained in:
@@ -102,7 +102,7 @@ export class File {
|
||||
const metadata = await this.getMetaData();
|
||||
await metadata.setLock({
|
||||
lock: 'locked',
|
||||
expires: new Date(Date.now() + (optionsArg?.timeoutMillis || 1000)),
|
||||
expires: Date.now() + (optionsArg?.timeoutMillis || 1000),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -116,7 +116,10 @@ export class File {
|
||||
*/
|
||||
force?: boolean;
|
||||
}) {
|
||||
|
||||
const metadata = await this.getMetaData();
|
||||
await metadata.removeLock({
|
||||
force: optionsArg?.force,
|
||||
});
|
||||
}
|
||||
|
||||
public async updateWithContents(optionsArg: {
|
||||
@@ -146,9 +149,27 @@ export class File {
|
||||
* @param updatedMetadata
|
||||
*/
|
||||
public async getMetaData() {
|
||||
if (this.name.endsWith('.metadata')) {
|
||||
throw new Error('metadata files cannot have metadata');
|
||||
}
|
||||
const metadata = await MetaData.createForFile({
|
||||
file: this,
|
||||
});
|
||||
return metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* gets the contents as json
|
||||
*/
|
||||
public async getJsonData() {
|
||||
const json = await this.getContentsAsString();
|
||||
const parsed = await JSON.parse(json);
|
||||
return parsed;
|
||||
}
|
||||
|
||||
public async writeJsonData(dataArg: any) {
|
||||
await this.updateWithContents({
|
||||
contents: JSON.stringify(dataArg),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user