1
0
mirror of https://github.com/koloml/furbooru-tagging-assistant.git synced 2025-12-24 07:12:57 +00:00

Extracted method to import directly from object

This commit is contained in:
2025-02-20 20:32:18 +04:00
parent 5dc41700b8
commit f67a321a66

View File

@@ -32,13 +32,7 @@ export default class EntitiesTransporter<EntityType> {
this.#targetEntityConstructor = entityConstructor;
}
importFromJSON(jsonString: string): EntityType {
const importedObject = this.#tryParsingAsJSON(jsonString);
if (!importedObject) {
throw new Error('Invalid JSON!');
}
importFromObject(importedObject: Record<string, any>): EntityType {
validateImportedEntity(
this.#entityName,
importedObject,
@@ -50,6 +44,16 @@ export default class EntitiesTransporter<EntityType> {
);
}
importFromJSON(jsonString: string): EntityType {
const importedObject = this.#tryParsingAsJSON(jsonString);
if (!importedObject) {
throw new Error('Invalid JSON!');
}
return this.importFromObject(importedObject);
}
importFromCompressedJSON(compressedJsonString: string): EntityType {
return this.importFromJSON(
decompressFromEncodedURIComponent(compressedJsonString)