github.com/readium/readium-lcp-server@v0.0.0-20240101192032-6e95190e99f1/frontend/manage/app/components/resource.service.ts (about) 1 import { Injectable } from '@angular/core'; 2 import { Http } from '@angular/http'; 3 import 'rxjs/add/operator/toPromise'; 4 import { Resource } from './resource'; 5 6 declare var Config: any; // this comes from the autogenerated config.js file 7 @Injectable() 8 export class ResourceService { 9 private resourceUrl = Config.lcp.url + '/contents'; 10 11 constructor (private http: Http) { } 12 getResources(): Promise<Resource[]> { 13 return this.http.get(this.resourceUrl) 14 .toPromise() 15 .then(function (response) { 16 let resources: Resource[] = []; 17 for (let jsonResult of response.json()) { 18 resources[resources.length] = { 19 id: jsonResult.id, location: jsonResult.location, length: jsonResult.length, sha256: jsonResult.sha356 20 }; 21 } 22 return resources; 23 }) 24 .catch(this.handleError); 25 } 26 27 private handleError(error: any): Promise<any> { 28 console.error('An error occurred', error); 29 return Promise.reject(error.message || error); 30 } 31 getUser(id: string): Promise<Resource> { 32 return this.getResources() 33 .then(resources => resources.find(resource => resource.id === id)); 34 } 35 }