diff --git a/examples/implementation/FileLibraryStorage.ts b/examples/implementation/FileLibraryStorage.ts index 47b1ad5cd..102929ac8 100644 --- a/examples/implementation/FileLibraryStorage.ts +++ b/examples/implementation/FileLibraryStorage.ts @@ -41,7 +41,7 @@ export default class FileLibraryStorage implements ILibraryStorage { filename: string, stream: Stream ): Promise { - if (!(await this.getId(library))) { + if (!(await this.libraryExists(library))) { throw new Error( `Can't add file ${filename} to library ${LibraryName.toUberName( library @@ -62,7 +62,7 @@ export default class FileLibraryStorage implements ILibraryStorage { * @returns {Promise} */ public async clearLibraryFiles(library: ILibraryName): Promise { - if (!(await this.getId(library))) { + if (!(await this.libraryExists(library))) { throw new Error( `Can't clear library ${LibraryName.toUberName( library @@ -110,19 +110,6 @@ export default class FileLibraryStorage implements ILibraryStorage { ); } - /** - * Returns the id of an installed library. - * @param {ILibraryName} library The library to get the id for - * @returns {Promise} the id or undefined if the library is not installed - */ - public async getId(library: ILibraryName): Promise { - const libraryPath = this.getFullPath(library, 'library.json'); - if (await fsExtra.pathExists(libraryPath)) { - return crc32(libraryPath); - } - return undefined; - } - /** * Returns all installed libraries or the installed libraries that have the machine names in the arguments. * @param {...string[]} machineNames (optional) only return libraries that have these machine names @@ -195,7 +182,6 @@ export default class FileLibraryStorage implements ILibraryStorage { this.getFullPath(library, 'library.json'), libraryMetadata ); - library.id = await this.getId(library); return library; } catch (error) { await fsExtra.remove(libPath); @@ -203,6 +189,15 @@ export default class FileLibraryStorage implements ILibraryStorage { } } + /** + * Checks if the library has been installed. + * @param name the library name + * @returns true if the library has been installed + */ + public async libraryExists(name: ILibraryName): Promise { + return fsExtra.pathExists(this.getDirectoryPath(name)); + } + /** * Gets a list of all library files that exist for this library. * @param {ILibraryName} library @@ -257,7 +252,6 @@ export default class FileLibraryStorage implements ILibraryStorage { libraryMetadata ); const newLibrary = InstalledLibrary.fromMetadata(libraryMetadata); - newLibrary.id = await this.getId(newLibrary); return newLibrary; } diff --git a/src/ContentTypeInformationRepository.ts b/src/ContentTypeInformationRepository.ts index e8ff46e2d..2889ee476 100644 --- a/src/ContentTypeInformationRepository.ts +++ b/src/ContentTypeInformationRepository.ts @@ -187,7 +187,6 @@ export default class ContentTypeInformationRepository { 'icon.svg' ) : undefined, - id: localLib.id, installed: true, isUpToDate: true, localMajorVersion: localLib.majorVersion, @@ -245,7 +244,6 @@ export default class ContentTypeInformationRepository { hubLib.canInstall = this.canInstallLibrary(hubLib, user); hubLib.isUpToDate = true; } else { - hubLib.id = localLib.id; hubLib.installed = true; hubLib.restricted = this.libraryIsRestricted(localLib) && diff --git a/src/InstalledLibrary.ts b/src/InstalledLibrary.ts index e089919a2..24181408b 100644 --- a/src/InstalledLibrary.ts +++ b/src/InstalledLibrary.ts @@ -20,7 +20,6 @@ export default class InstalledLibrary implements IInstalledLibrary { this.majorVersion = majorVersion; this.minorVersion = minorVersion; this.patchVersion = patchVersion; - this.id = undefined; this.title = undefined; this.runnable = undefined; this.restricted = restricted; @@ -35,8 +34,6 @@ export default class InstalledLibrary implements IInstalledLibrary { public embedTypes?: ('iframe' | 'div')[]; public fullscreen?: 0 | 1; public h?: number; - public id: number; - public libraryId: number; public license?: string; public metadataSettings?: { disable: 0 | 1; disableExtraTitleField: 0 | 1 }; public preloadedCss?: IPath[]; diff --git a/src/LibraryManager.ts b/src/LibraryManager.ts index 3e17ee537..c19e1abb3 100644 --- a/src/LibraryManager.ts +++ b/src/LibraryManager.ts @@ -61,17 +61,6 @@ export default class LibraryManager { return this.libraryStorage.getFileStream(library, file); } - /** - * Get id to an existing installed library. - * If version number is not specified, the newest version will be returned. - * @param {ILibraryName} library Note that patch version is ignored. - * @returns {Promise} The id of the specified library or undefined (if not installed). - */ - public async getId(library: ILibraryName): Promise { - log.debug(`getting id for library ${LibraryName.toUberName(library)}`); - return this.libraryStorage.getId(library); - } - /** * Get a list of the currently installed libraries. * @param {String[]?} machineNames (if supplied) only return results for the machines names in the list @@ -89,7 +78,6 @@ export default class LibraryManager { const installedLib = InstalledLibrary.fromName(libName); const info = await this.loadLibrary(libName); installedLib.patchVersion = info.patchVersion; - installedLib.id = info.libraryId; installedLib.runnable = info.runnable; installedLib.title = info.title; return installedLib; @@ -157,7 +145,7 @@ export default class LibraryManager { const newLibraryMetadata: ILibraryMetadata = await fsExtra.readJSON( `${directory}/library.json` ); - if (await this.getId(newLibraryMetadata)) { + if (await this.libraryExists(newLibraryMetadata)) { // Check if library is already installed. if (await this.isPatchedLibrary(newLibraryMetadata)) { // Update the library if it is only a patch of an existing library @@ -209,17 +197,7 @@ export default class LibraryManager { * @returns true if the library has been installed */ public async libraryExists(library: LibraryName): Promise { - const installed = await this.getInstalled([library.machineName]); - if (!installed || !installed[library.machineName]) { - return false; - } - return ( - installed[library.machineName].find( - l => - l.majorVersion === library.majorVersion && - l.minorVersion === l.minorVersion - ) !== undefined - ); + return this.libraryStorage.libraryExists(library); } /** @@ -349,7 +327,7 @@ export default class LibraryManager { library, 'library.json' ); - libraryMetadata.libraryId = await this.getId(library); + libraryMetadata.libraryId = await this.libraryExists(library); return libraryMetadata; } catch (ignored) { log.warn( @@ -379,7 +357,7 @@ export default class LibraryManager { * @returns {Promise} true if the library is ok. Throws errors if not. */ private async checkConsistency(library: ILibraryName): Promise { - if (!(await this.libraryStorage.getId(library))) { + if (!(await this.libraryExists(library))) { log.error( `Error in library ${LibraryName.toUberName( library diff --git a/src/types.ts b/src/types.ts index 6ebcd50c7..fc5cda83e 100644 --- a/src/types.ts +++ b/src/types.ts @@ -417,13 +417,6 @@ export interface ILibraryStorage { */ getFileStream(library: ILibraryName, file: string): ReadStream; - /** - * Returns the id of an installed library. - * @param library The library to get the id for - * @returns the id or undefined if the library is not installed - */ - getId(library: ILibraryName): Promise; - /** * Returns all installed libraries or the installed libraries that have the machine names in the arguments. * @param machineNames (optional) only return libraries that have these machine names @@ -451,6 +444,13 @@ export interface ILibraryStorage { restricted: boolean ): Promise; + /** + * Checks if the library has been installed. + * @param name the library name + * @returns true if the library has been installed + */ + libraryExists(name: ILibraryName): Promise; + /** * Gets a list of all library files that exist for this library. * @param library @@ -626,17 +626,6 @@ export interface ISemanticsEntry { * Objects of this interface represent installed libraries that have an id. */ export interface IInstalledLibrary extends ILibraryMetadata { - /** - * The id used internally to identify the library. Must be unique and assigned when the - * library is installed. Libraries whose machine name is identical but that have different - * major or minor version must also have different ids, while libraries that only differ in - * patch versions can have the same id (as they can't co-exist). - */ - id: number; - /** - * Unknown. Check if obsolete and to be removed. - */ - libraryId: number; /** * If set to true, the library can only be used be users who have this special * privilege.