Skip to content

Commit

Permalink
Add logo and overview file paths as Group Source properties
Browse files Browse the repository at this point in the history
For now, this prevents hard-coding of file paths used across various
files.

In the future, this can facilitate allowing custom image formats for
individual group logos, which would need different file extensions.
  • Loading branch information
victorlin committed Sep 20, 2022
1 parent b9dd43d commit 25235ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/endpoints/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const deleteGroupLogo = async (req, res) => {
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group);

const method = "DELETE";
const url = await req.context.group.source.urlFor("group-logo.png", method);
const url = await req.context.group.source.urlFor(req.context.group.source.logoFile, method);
await deleteByUrls([url]);

return res.status(204).end();
Expand Down Expand Up @@ -75,7 +75,7 @@ const deleteGroupOverview = async (req, res) => {
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group);

const method = "DELETE";
const url = await req.context.group.source.urlFor("group-overview.md", method);
const url = await req.context.group.source.urlFor(req.context.group.source.overviewFile, method);
await deleteByUrls([url]);

return res.status(204).end();
Expand All @@ -93,7 +93,7 @@ async function sendGroupOverview(req, res) {
authz.assertAuthorized(req.user, authz.actions.Read, req.context.group);

return await proxyFromUpstream(req, res,
await req.context.group.source.urlFor("group-overview.md"),
await req.context.group.source.urlFor(req.context.group.source.overviewFile),
"text/markdown"
);
}
Expand All @@ -110,7 +110,7 @@ async function receiveGroupOverview(req, res) {
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group);

return await proxyToUpstream(req, res,
async (method, headers) => await req.context.group.source.urlFor("group-overview.md", method, headers),
async (method, headers) => await req.context.group.source.urlFor(req.context.group.source.overviewFile, method, headers),
"text/markdown"
);
}
Expand All @@ -127,7 +127,7 @@ async function sendGroupLogo(req, res) {
authz.assertAuthorized(req.user, authz.actions.Read, req.context.group);

return await proxyFromUpstream(req, res,
await req.context.group.source.urlFor("group-logo.png"),
await req.context.group.source.urlFor(req.context.group.source.logoFile),
"image/png"
);
}
Expand All @@ -144,7 +144,7 @@ async function receiveGroupLogo(req, res) {
authz.assertAuthorized(req.user, authz.actions.Write, req.context.group);

return await proxyToUpstream(req, res,
async (method, headers) => await req.context.group.source.urlFor("group-logo.png", method, headers),
async (method, headers) => await req.context.group.source.urlFor(req.context.group.source.logoFile, method, headers),
"image/png"
);
}
Expand Down
8 changes: 5 additions & 3 deletions src/sources/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class GroupSource extends Source {
constructor(name) {
super();
this.name = name;
this.logoFile = "group-logo.png";
this.overviewFile = "group-overview.md";
}

/**
Expand Down Expand Up @@ -141,7 +143,7 @@ class GroupSource extends Source {
: "";
const files = await this._listFiles(prefix);
return files
.filter((file) => file !== 'group-overview.md')
.filter((file) => file !== this.overviewFile)
.filter((file) => file.endsWith(".md"))
.map((file) => file
.replace(/[.]md$/, "")
Expand Down Expand Up @@ -200,8 +202,8 @@ class GroupSource extends Source {
try {
/* attempt to fetch customisable information from S3 bucket */
const [logoResponse, overviewResponse] = await Promise.all([
fetch(await this.urlFor("group-logo.png"), {cache: "no-cache"}),
fetch(await this.urlFor("group-overview.md"), {cache: "no-cache"}),
fetch(await this.urlFor(this.logoFile), {cache: "no-cache"}),
fetch(await this.urlFor(this.overviewFile), {cache: "no-cache"}),
]);

const logoSrc = logoResponse.status === 200
Expand Down

0 comments on commit 25235ff

Please sign in to comment.