-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8071320
commit a0d3c80
Showing
11 changed files
with
121 additions
and
9 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,86 @@ | ||
import {DEFAULT_BRANDING_LOGO, getConfig, PUBLIC_PATH, BRANDING_LOGO} from "../config"; | ||
import {root} from "../package"; | ||
import {join} from "node:path"; | ||
import {stat} from "fs/promises"; | ||
import {ok} from "../is"; | ||
import {ROOT_PUBLIC_PATH} from "../view"; | ||
import {readFile} from "node:fs/promises"; | ||
import mime from "mime"; | ||
|
||
|
||
function getPublicRoots() { | ||
const roots = [ | ||
ROOT_PUBLIC_PATH, | ||
]; | ||
const config = getConfig(); | ||
if (root !== config.root && config.root) { | ||
roots.unshift( | ||
join(config.root, PUBLIC_PATH || "public") | ||
); | ||
} | ||
return roots; | ||
} | ||
|
||
export async function getBrandingLogoBufferAndType() { | ||
const logo = await getBrandingLogoFile(); | ||
const buffer = await readFile(logo.path); | ||
// Could use blob here, but then we need to go from blob to buffer elsewhere | ||
return { | ||
buffer, | ||
type: mime.getType(logo.path) | ||
} | ||
} | ||
|
||
export async function getBrandingLogoFile() { | ||
|
||
const roots = getPublicRoots(); | ||
|
||
if (BRANDING_LOGO) { | ||
return getBrandingLogo(BRANDING_LOGO); | ||
} | ||
return getPublicLogo(); | ||
|
||
async function getBrandingLogo(logo: string) { | ||
const found = await getFirstFile(roots, [ | ||
logo | ||
]); | ||
ok(found, "Expected BRANDING_LOGO at PUBLIC_PATH"); | ||
return found; | ||
} | ||
|
||
async function getPublicLogo() { | ||
const found = await getFirstFile(roots, [ | ||
DEFAULT_BRANDING_LOGO, | ||
"logo.svg", | ||
"logo.png" | ||
]); | ||
ok(found, "Expected to find logo at root or BRANDING_LOGO"); | ||
return found; | ||
} | ||
|
||
async function getFirstFile(paths: string[], names: string[]) { | ||
for (const root of paths) { | ||
for (const name of names) { | ||
const path = join(root, name); | ||
if (await isFile(path)) { | ||
return { | ||
root, | ||
path, | ||
name, | ||
}; | ||
} | ||
} | ||
} | ||
return undefined; | ||
} | ||
|
||
} | ||
|
||
async function isFile(path: string) { | ||
try { | ||
const fileStat = await stat(path); | ||
return fileStat.isFile(); | ||
} catch { | ||
return false; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ export interface Config extends | |
VirtualEventConfig { | ||
name: string; | ||
version: string; | ||
root: string; | ||
} |
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,15 @@ | ||
import {FastifyInstance} from "fastify"; | ||
import {getBrandingLogoBufferAndType} from "../../branding"; | ||
|
||
export async function brandingRoutes(fastify: FastifyInstance) { | ||
try { | ||
fastify.get("/branding/logo", { | ||
async handler(request, response) { | ||
const { buffer, type } = await getBrandingLogoBufferAndType(); | ||
response.header("Content-Type", type); | ||
response.send(buffer); | ||
} | ||
}) | ||
} catch {} | ||
|
||
} |
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