atmosphere explorer
at main 59 lines 2.1 kB view raw
1import { mkdirSync, writeFileSync } from "fs"; 2import { dirname } from "path"; 3import { fileURLToPath } from "url"; 4 5const __filename = fileURLToPath(import.meta.url); 6const __dirname = dirname(__filename); 7 8const domain = process.env.APP_DOMAIN || "pdsls.dev"; 9const protocol = process.env.APP_PROTOCOL || "https"; 10const baseUrl = `${protocol}://${domain}`; 11 12const configs = { 13 oauth: { 14 name: "OAuth metadata", 15 path: `${__dirname}/../public/oauth-client-metadata.json`, 16 content: 17 JSON.stringify( 18 { 19 client_id: `${baseUrl}/oauth-client-metadata.json`, 20 client_name: "PDSls", 21 client_uri: baseUrl, 22 logo_uri: `${baseUrl}/favicon.ico`, 23 redirect_uris: [`${baseUrl}/`], 24 scope: "atproto repo:*?action=create repo:*?action=update repo:*?action=delete blob:*/*", 25 grant_types: ["authorization_code", "refresh_token"], 26 response_types: ["code"], 27 token_endpoint_auth_method: "none", 28 application_type: "web", 29 dpop_bound_access_tokens: true, 30 }, 31 null, 32 2, 33 ) + "\n", 34 }, 35 opensearch: { 36 name: "OpenSearch XML", 37 path: `${__dirname}/../public/opensearch.xml`, 38 content: `<?xml version="1.0" encoding="UTF-8"?> 39<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/" xmlns:moz="http://www.mozilla.org/2006/browser/search/"> 40 <ShortName>PDSls</ShortName> 41 <Description>Search the Atmosphere</Description> 42 <InputEncoding>UTF-8</InputEncoding> 43 <Image width="16" height="16" type="image/x-icon">${baseUrl}/favicon.ico</Image> 44 <Url type="text/html" method="get" template="${baseUrl}/?q={searchTerms}"/> 45 <moz:SearchForm>${baseUrl}</moz:SearchForm> 46</OpenSearchDescription>`, 47 }, 48}; 49 50try { 51 Object.values(configs).forEach((config) => { 52 mkdirSync(dirname(config.path), { recursive: true }); 53 writeFileSync(config.path, config.content); 54 console.log(`Generated ${config.name} for ${baseUrl}`); 55 }); 56} catch (error) { 57 console.error("Failed to generate files:", error); 58 process.exit(1); 59}