Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
feat(config)!: update config file for better iiif support (DSP-1880) (#…
…511) * chore(config)!: consistent config * refactor(app): move app init service to app root * refactor(representation): upload service was already there * feat(upload)!: new iiif url config
- Loading branch information
1 parent
fc7ea5c
commit b799600
Showing
14 changed files
with
161 additions
and
232 deletions.
There are no files selected for viewing
File renamed without changes.
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,86 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { KnoraApiConfig } from '@dasch-swiss/dsp-js'; | ||
import { DspIiifConfig } from './main/declarations/dsp-iiif-config'; | ||
|
||
@Injectable({ | ||
providedIn: 'root' | ||
}) | ||
export class AppInitService { | ||
|
||
dspApiConfig: KnoraApiConfig; | ||
dspIiifConfig: DspIiifConfig; | ||
|
||
config: object; | ||
|
||
constructor() { | ||
} | ||
|
||
/** | ||
* fetches and initialises the configuration. | ||
* | ||
* @param path path to the config file. | ||
* @param env environment to be used (dev or prod). | ||
*/ | ||
Init(path: string, env: { name: string; production: boolean }): Promise<void> { | ||
|
||
return new Promise<void>((resolve, reject) => { | ||
fetch(`${path}/config.${env.name}.json`).then( | ||
(response: Response) => response.json()).then(dspAppConfig => { | ||
|
||
|
||
// check for presence of apiProtocol and apiHost | ||
if (typeof dspAppConfig.apiProtocol !== 'string' || typeof dspAppConfig.apiHost !== 'string') { | ||
throw new Error('config misses required members: apiProtocol and/or apiHost'); | ||
} | ||
|
||
// make input type safe | ||
const apiPort = (typeof dspAppConfig.apiPort === 'number' ? dspAppConfig.apiPort : null); | ||
const apiPath = (typeof dspAppConfig.apiPath === 'string' ? dspAppConfig.apiPath : ''); | ||
const jsonWebToken = (typeof dspAppConfig.jsonWebToken === 'string' ? dspAppConfig.jsonWebToken : ''); | ||
const logErrors = (typeof dspAppConfig.logErrors === 'boolean' ? dspAppConfig.logErrors : false); | ||
|
||
// init dsp-api configuration | ||
this.dspApiConfig = new KnoraApiConfig( | ||
dspAppConfig.apiProtocol, | ||
dspAppConfig.apiHost, | ||
apiPort, | ||
apiPath, | ||
jsonWebToken, | ||
logErrors | ||
); | ||
|
||
const iiifPort = (typeof dspAppConfig.iiifPort === 'number' ? dspAppConfig.iiifPort : null); | ||
const iiifPath = (typeof dspAppConfig.iiifPath === 'string' ? dspAppConfig.iiifPath : ''); | ||
|
||
// init iiif configuration | ||
this.dspIiifConfig = new DspIiifConfig( | ||
dspAppConfig.iiifProtocol, | ||
dspAppConfig.iiifHost, | ||
iiifPort, | ||
iiifPath | ||
); | ||
|
||
// get all options from config | ||
this.config = dspAppConfig; | ||
|
||
// set sanitized standard config options | ||
this.config['apiProtocol'] = dspAppConfig.apiProtocol; | ||
this.config['apiHost'] = dspAppConfig.apiHost; | ||
this.config['apiPort'] = apiPort; | ||
this.config['apiPath'] = apiPath; | ||
this.config['jsonWebToken'] = jsonWebToken; | ||
this.config['logErrors'] = logErrors; | ||
this.config['iiifProtocol'] = dspAppConfig.iiifProtocol; | ||
this.config['iiifHost'] = dspAppConfig.iiifHost; | ||
this.config['iiifPort'] = iiifPort; | ||
this.config['iiifPath'] = iiifPath; | ||
this.config['iiifUrl'] = this.dspIiifConfig.iiifUrl; | ||
|
||
resolve(); | ||
} | ||
).catch((err) => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* configuration to instantiate the iiif url. | ||
* | ||
* @category Config | ||
*/ | ||
export class DspIiifConfig { | ||
|
||
static readonly PROTOCOL_HTTP = 'http'; | ||
static readonly PROTOCOL_HTTPS = 'https'; | ||
|
||
static readonly DEFAULT_PORT_HTTP = 80; | ||
static readonly DEFAULT_PORT_HTTPS = 443; | ||
|
||
/** | ||
* the full IIIF URL | ||
*/ | ||
get iiifUrl(): string { | ||
return ( | ||
(this.iiifProtocol + '://' + this.iiifHost) + | ||
(this.iiifPort !== null ? ':' + this.iiifPort : '') + | ||
this.iiifPath | ||
); | ||
} | ||
|
||
/** | ||
* @param iiifProtocol the protocol of the API (http or https) | ||
* @param iiifHost the DSP-API base URL | ||
* @param iiifPort the port of DSP-API | ||
* @param iiifPath the base path following host and port, if any. | ||
*/ | ||
constructor(public iiifProtocol: 'http' | 'https', | ||
public iiifHost: string, | ||
public iiifPort: number | null = null, | ||
public iiifPath: string = '') { | ||
|
||
// remove port in case it's the default one | ||
if (iiifProtocol === DspIiifConfig.PROTOCOL_HTTP && iiifPort === DspIiifConfig.DEFAULT_PORT_HTTP) { | ||
this.iiifPort = null; | ||
} else if (iiifProtocol === DspIiifConfig.PROTOCOL_HTTPS && iiifPort === DspIiifConfig.DEFAULT_PORT_HTTPS) { | ||
this.iiifPort = null; | ||
} | ||
|
||
} | ||
} |
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
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
100 changes: 0 additions & 100 deletions
100
src/app/workspace/resource/services/upload-file.service.spec.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.