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AI,CAAC,cAAc,CAAC,CAAC;gBAC9B,CAAC,CAAC,CAAC;gBAEH,KAAK,CAAC,yBAAuB,MAAI,CAAC,CAAC,CAAG,CAAC,CAAC;gBAExC,IAAM,KAAK,GAAG,aAAa,CAAC,KAAK,CAAC,MAAM,EAAE,MAAI,EAAE;oBAC5C,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;oBAElB,GAAG,EAAE,OAAO,CAAC,GAAG;iBAEnB,CAAC,CAEG;gBACL,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,IAAI;oBACzB,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;gBAC3B,CAAC,CAAC,CAAC;gBACH,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,UAAC,IAAI;oBACzB,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;gBAC3B,CAAC,CAAC,CAAC;aACN;YACD,OAAO,SAAS,CAAC;SACpB;QACD,IAAI,CAAC,wBAAwB,GAAG,KAAK,CAAC;QACtC,IAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,gBAAgB,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;QAC7E,IAAI,CAAC,OAAO,EAAE;YACV,OAAO,SAAS,CAAC;SACpB;QACD,IAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAExC,IAAI,CAAC,oBAAoB,GAAG,gCAAiB,CAAW,IAAI,EAAE,gBAAQ,CAAC,CAAC;QACxE,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;IACL,aAAC;AAAD,CAAC,AAjYD,IAiYC;AAjYY,wBAAM","sourcesContent":["// ==LICENSE-BEGIN==\n// Copyright 2017 European Digital Reading Lab. All rights reserved.\n// Licensed to the Readium Foundation under one or more contributor license agreements.\n// Use of this source code is governed by a BSD-style license\n// that can be found in the LICENSE file exposed on Github (readium) in the project repository.\n// ==LICENSE-END==\n\nimport * as child_process from \"child_process\";\nimport * as debug_ from \"debug\";\nimport * as express from \"express\";\nimport * as fs from \"fs\";\nimport * as http from \"http\";\nimport * as https from \"https\";\nimport * as path from \"path\";\nimport { tmpNameSync } from \"tmp\";\n\nimport { TaJsonDeserialize } from \"@r2-lcp-js/serializable\";\nimport { OPDSFeed } from \"@r2-opds-js/opds/opds2/opds2\";\nimport { Publication } from \"@r2-shared-js/models/publication\";\nimport { PublicationParsePromise } from \"@r2-shared-js/parser/publication-parser\";\nimport { encodeURIComponent_RFC3986 } from \"@r2-utils-js/_utils/http/UrlUtils\";\n\nimport { CertificateData, generateSelfSignedData } from \"../utils/self-signed\";\nimport { _jsonPath, _show } from \"./request-ext\";\nimport { serverAssets } from \"./server-assets\";\nimport { serverLCPLSD_show } from \"./server-lcp-lsd-show\";\nimport { serverManifestJson } from \"./server-manifestjson\";\nimport { serverMediaOverlays } from \"./server-mediaoverlays\";\nimport { serverOPDS_browse_v1 } from \"./server-opds-browse-v1\";\nimport { serverOPDS_browse_v2 } from \"./server-opds-browse-v2\";\nimport { serverOPDS_convert_v1_to_v2 } from \"./server-opds-convert-v1-to-v2\";\nimport { serverOPDS_local_feed } from \"./server-opds-local-feed\";\nimport { serverPub } from \"./server-pub\";\nimport { serverRoot } from \"./server-root\";\nimport { IHTTPHeaderNameValue, serverSecure, serverSecureHTTPHeader } from \"./server-secure\";\nimport { serverRemotePub } from \"./server-url\";\nimport { serverVersion } from \"./server-version\";\n\nconst debug = debug_(\"r2:streamer#http/server\");\n\ninterface IPathPublicationMap { [key: string]: any; }\n\nexport interface ServerData extends CertificateData {\n urlScheme: string;\n urlHost: string;\n urlPort: number;\n}\n\nexport interface IServerOptions {\n disableReaders?: boolean;\n disableDecryption?: boolean; /* excludes obfuscated fonts */\n disableRemotePubUrl?: boolean;\n disableOPDS?: boolean;\n maxPrefetchLinks?: number;\n}\n\n// this ceiling value seems very arbitrary ... what would be a reasonable default value?\n// ... based on what metric, any particular HTTP server or client implementation?\nexport const MAX_PREFETCH_LINKS = 10;\n\nexport class Server {\n public readonly disableReaders: boolean;\n public readonly disableDecryption: boolean;\n public readonly disableRemotePubUrl: boolean;\n public readonly disableOPDS: boolean;\n public readonly maxPrefetchLinks: number;\n\n public readonly lcpBeginToken = \"*-\";\n public readonly lcpEndToken = \"-*\";\n\n private readonly publications: string[];\n private publicationsOPDSfeed: OPDSFeed | undefined;\n private publicationsOPDSfeedNeedsUpdate: boolean;\n private readonly pathPublicationMap: IPathPublicationMap;\n private creatingPublicationsOPDS: boolean;\n private readonly opdsJsonFilePath: string;\n\n private readonly expressApp: express.Application;\n\n private httpServer: http.Server | undefined;\n private httpsServer: https.Server | undefined;\n\n private serverData: ServerData | undefined;\n\n constructor(options?: IServerOptions) {\n\n this.disableReaders = options && options.disableReaders ? options.disableReaders : false;\n this.disableDecryption = options && options.disableDecryption ? options.disableDecryption : false;\n this.disableRemotePubUrl = options && options.disableRemotePubUrl ? options.disableRemotePubUrl : false;\n this.disableOPDS = options && options.disableOPDS ? options.disableOPDS : false;\n\n // note: zero not allowed (fallback to default MAX_PREFETCH_LINKS). use -1 to disable ceiling value.\n this.maxPrefetchLinks = options && options.maxPrefetchLinks ? options.maxPrefetchLinks : MAX_PREFETCH_LINKS;\n\n this.publications = [];\n this.pathPublicationMap = {};\n this.publicationsOPDSfeed = undefined;\n this.publicationsOPDSfeedNeedsUpdate = true;\n this.creatingPublicationsOPDS = false;\n\n this.opdsJsonFilePath = tmpNameSync({ prefix: \"readium2-OPDS2-\", postfix: \".json\" });\n\n this.expressApp = express();\n // this.expressApp.enable('strict routing');\n\n serverSecure(this, this.expressApp);\n\n // https://expressjs.com/en/4x/api.html#express.static\n const staticOptions = {\n etag: false,\n };\n if (!this.disableReaders) {\n this.expressApp.use(\"/readerNYPL\", express.static(\"misc/readers/reader-NYPL\", staticOptions));\n this.expressApp.use(\"/readerHADRIEN\", express.static(\"misc/readers/reader-HADRIEN\", staticOptions));\n }\n\n serverRoot(this, this.expressApp);\n serverVersion(this, this.expressApp);\n\n if (!this.disableRemotePubUrl) {\n serverRemotePub(this, this.expressApp);\n serverLCPLSD_show(this, this.expressApp);\n }\n if (!this.disableOPDS) {\n serverOPDS_browse_v1(this, this.expressApp);\n serverOPDS_browse_v2(this, this.expressApp);\n serverOPDS_local_feed(this, this.expressApp);\n serverOPDS_convert_v1_to_v2(this, this.expressApp);\n }\n\n const routerPathBase64: express.Router = serverPub(this, this.expressApp);\n serverManifestJson(this, routerPathBase64);\n serverMediaOverlays(this, routerPathBase64);\n serverAssets(this, routerPathBase64);\n }\n\n // TODO: HTTP header `X-Robots-Tag` === `none`?\n public preventRobots() {\n this.expressApp.get(\"/robots.txt\", (_req: express.Request, res: express.Response) => {\n\n const robotsTxt = `User-agent: *\nDisallow: /\n`;\n res.header(\"Content-Type\", \"text/plain\");\n res.status(200).send(robotsTxt);\n });\n }\n\n public expressUse(pathf: string, func: express.Handler) {\n this.expressApp.use(pathf, func);\n }\n\n public expressGet(paths: string[], func: express.Handler) {\n this.expressApp.get(paths, func);\n }\n\n public isStarted(): boolean {\n return (typeof this.serverInfo() !== \"undefined\") &&\n (typeof this.httpServer !== \"undefined\") ||\n (typeof this.httpsServer !== \"undefined\");\n }\n\n public isSecured(): boolean {\n return (typeof this.serverInfo() !== \"undefined\") &&\n (typeof this.httpsServer !== \"undefined\");\n }\n\n public getSecureHTTPHeader(url: string): IHTTPHeaderNameValue | undefined {\n return serverSecureHTTPHeader(this, url);\n }\n\n public async start(port: number, secure: boolean): Promise<ServerData> {\n\n if (this.isStarted()) {\n return Promise.resolve(this.serverInfo() as ServerData);\n }\n\n let envPort: number = 0;\n try {\n envPort = process.env.PORT ? parseInt(process.env.PORT as string, 10) : 0;\n } catch (err) {\n debug(err);\n envPort = 0;\n }\n const p = port || envPort || 3000;\n debug(`PORT: ${port} || ${envPort} || 3000 => ${p}`);\n\n if (secure) {\n this.httpServer = undefined;\n\n return new Promise<ServerData>(async (resolve, reject) => {\n let certData: CertificateData | undefined;\n try {\n certData = await generateSelfSignedData();\n } catch (err) {\n debug(err);\n reject(\"err\");\n return;\n }\n\n this.httpsServer = https.createServer({ key: certData.private, cert: certData.cert },\n this.expressApp).listen(p, () => {\n\n this.serverData = {\n ...certData,\n urlHost: \"127.0.0.1\",\n urlPort: p, // this.httpsServer.address().port\n urlScheme: \"https\",\n } as ServerData;\n resolve(this.serverData);\n });\n });\n } else {\n this.httpsServer = undefined;\n\n return new Promise<ServerData>((resolve, _reject) => {\n this.httpServer = http.createServer(this.expressApp).listen(p, () => {\n\n this.serverData = {\n urlHost: \"127.0.0.1\",\n urlPort: p, // this.httpsServer.address().port\n urlScheme: \"http\",\n } as ServerData;\n resolve(this.serverData);\n });\n // this.httpServer = this.expressApp.listen(p, () => {\n // debug(`http://localhost:${p}`);\n // });\n });\n }\n }\n\n public stop() {\n if (this.isStarted()) {\n if (this.httpServer) {\n this.httpServer.close();\n this.httpServer = undefined;\n }\n if (this.httpsServer) {\n this.httpsServer.close();\n this.httpsServer = undefined;\n }\n this.serverData = undefined;\n this.uncachePublications();\n }\n }\n\n public serverInfo(): ServerData | undefined {\n return this.serverData;\n }\n\n public serverUrl(): string | undefined {\n if (!this.isStarted()) {\n return undefined;\n }\n const info = this.serverInfo();\n if (!info) {\n return undefined;\n }\n\n // This is important, because browsers collapse the standard HTTP and HTTPS ports,\n // and we don't normalise this elsewhere in consumer code!\n // (which means critical URL prefix matching / syntax comparisons would fail otherwise :(\n if (info.urlPort === 443 || info.urlPort === 80) {\n return `${info.urlScheme}://${info.urlHost}`;\n }\n return `${info.urlScheme}://${info.urlHost}:${info.urlPort}`;\n\n // const port = this.httpServer ? this.httpServer.address().port :\n // (this.httpsServer ? this.httpsServer.address().port : 0);\n // return this.isStarted() ?\n // `${this.httpsServer ? \"https:\" : \"http:\"}//127.0.0.1:${port}` :\n // undefined;\n }\n\n public setResponseCacheHeaders(res: express.Response, enableCaching: boolean) {\n\n if (enableCaching) {\n res.setHeader(\"Cache-Control\", \"public,max-age=86400\");\n } else {\n res.setHeader(\"Cache-Control\", \"no-cache, no-store, must-revalidate\");\n res.setHeader(\"Pragma\", \"no-cache\");\n res.setHeader(\"Expires\", \"0\");\n }\n }\n\n public setResponseCORS(res: express.Response) {\n res.setHeader(\"Access-Control-Allow-Origin\",\n \"*\");\n\n res.setHeader(\"Access-Control-Allow-Methods\",\n \"GET, HEAD, OPTIONS\"); // POST, DELETE, PUT, PATCH\n\n res.setHeader(\"Access-Control-Allow-Headers\",\n // tslint:disable-next-line:max-line-length\n \"Content-Type, Content-Length, Accept-Ranges, Content-Range, Range, Link, Transfer-Encoding, X-Requested-With, Authorization, Accept, Origin, User-Agent, DNT, Cache-Control, Keep-Alive, If-Modified-Since\");\n\n res.setHeader(\"Access-Control-Expose-Headers\",\n // tslint:disable-next-line:max-line-length\n \"Content-Type, Content-Length, Accept-Ranges, Content-Range, Range, Link, Transfer-Encoding, X-Requested-With, Authorization, Accept, Origin, User-Agent, DNT, Cache-Control, Keep-Alive, If-Modified-Since\");\n }\n\n public addPublications(pubs: string[]): string[] {\n pubs.forEach((pub) => {\n if (this.publications.indexOf(pub) < 0) {\n this.publicationsOPDSfeedNeedsUpdate = true;\n this.publications.push(pub);\n }\n });\n\n return pubs.map((pub) => {\n const pubid = encodeURIComponent_RFC3986(Buffer.from(pub).toString(\"base64\"));\n return `/pub/${pubid}/manifest.json`;\n });\n }\n\n public removePublications(pubs: string[]): string[] {\n pubs.forEach((pub) => {\n this.uncachePublication(pub);\n const i = this.publications.indexOf(pub);\n if (i >= 0) {\n this.publicationsOPDSfeedNeedsUpdate = true;\n this.publications.splice(i, 1);\n }\n });\n\n return pubs.map((pub) => {\n const pubid = encodeURIComponent_RFC3986(Buffer.from(pub).toString(\"base64\"));\n return `/pub/${pubid}/manifest.json`;\n });\n }\n\n public getPublications(): string[] {\n return this.publications;\n }\n\n public async loadOrGetCachedPublication(filePath: string): Promise<Publication> {\n\n let publication = this.cachedPublication(filePath);\n if (!publication) {\n\n // const fileName = path.basename(pathBase64Str);\n // const ext = path.extname(fileName).toLowerCase();\n\n try {\n publication = await PublicationParsePromise(filePath);\n } catch (err) {\n debug(err);\n return Promise.reject(err);\n }\n\n this.cachePublication(filePath, publication);\n }\n // return Promise.resolve(publication);\n return publication;\n }\n\n public isPublicationCached(filePath: string): boolean {\n return typeof this.cachedPublication(filePath) !== \"undefined\";\n }\n\n public cachedPublication(filePath: string): Publication | undefined {\n return this.pathPublicationMap[filePath];\n }\n\n public cachePublication(filePath: string, pub: Publication) {\n // TODO: implement LRU caching algorithm? Anything smarter than this will do!\n if (!this.isPublicationCached(filePath)) {\n this.pathPublicationMap[filePath] = pub;\n }\n }\n\n public uncachePublication(filePath: string) {\n if (this.isPublicationCached(filePath)) {\n const pub = this.cachedPublication(filePath);\n if (pub) {\n pub.freeDestroy();\n }\n this.pathPublicationMap[filePath] = undefined;\n delete this.pathPublicationMap[filePath];\n }\n }\n\n public uncachePublications() {\n Object.keys(this.pathPublicationMap).forEach((filePath) => {\n this.uncachePublication(filePath);\n });\n }\n\n public publicationsOPDS(): OPDSFeed | undefined {\n\n if (this.publicationsOPDSfeedNeedsUpdate) {\n this.publicationsOPDSfeed = undefined;\n if (fs.existsSync(this.opdsJsonFilePath)) {\n fs.unlinkSync(this.opdsJsonFilePath);\n }\n }\n\n if (this.publicationsOPDSfeed) {\n return this.publicationsOPDSfeed;\n }\n\n debug(`OPDS2.json => ${this.opdsJsonFilePath}`);\n if (!fs.existsSync(this.opdsJsonFilePath)) {\n if (!this.creatingPublicationsOPDS) {\n this.creatingPublicationsOPDS = true;\n\n this.publicationsOPDSfeedNeedsUpdate = false;\n\n const jsFile = path.join(__dirname, \"opds2-create-cli.js\");\n const args = [jsFile, this.opdsJsonFilePath];\n this.publications.forEach((pub) => {\n const filePathBase64 = encodeURIComponent_RFC3986(Buffer.from(pub).toString(\"base64\"));\n args.push(filePathBase64);\n });\n // debug(\"SPAWN OPDS2 create: %o\", args);\n debug(`SPAWN OPDS2-create: ${args[0]}`);\n\n const child = child_process.spawn(\"node\", args, {\n cwd: process.cwd(),\n // detached: true,\n env: process.env,\n // stdio: [\"ignore\"],\n })\n // .unref()\n ;\n child.stdout.on(\"data\", (data) => {\n debug(data.toString());\n });\n child.stderr.on(\"data\", (data) => {\n debug(data.toString());\n });\n }\n return undefined;\n }\n this.creatingPublicationsOPDS = false;\n const jsonStr = fs.readFileSync(this.opdsJsonFilePath, { encoding: \"utf8\" });\n if (!jsonStr) {\n return undefined;\n }\n const json = global.JSON.parse(jsonStr);\n\n this.publicationsOPDSfeed = TaJsonDeserialize<OPDSFeed>(json, OPDSFeed);\n return this.publicationsOPDSfeed;\n }\n}\n"]}
\No newline at end of file