Skip to content

Commit

Permalink
Fallback to hardcoded config url, update mapeo-config-renderer, remov…
Browse files Browse the repository at this point in the history
…e cloud deploy action
  • Loading branch information
luandro committed Apr 10, 2024
1 parent bb5ca9c commit 31d1989
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/ssh-deploy.yml

This file was deleted.

1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ RUN yarn deploy

ENV NODE_ENV production
ENV ROOT_DIR /tmp
ENV DEFAULT_CONFIG_URL https://github.com/digidem/mapeo-default-config/releases/download/v3.6.1/mapeo-default-settings-v3.6.1.mapeosettings
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"date-fns": "^2.30.0",
"formidable": "2.x",
"mapeo-config-deconstructor": "^2.0.6",
"mapeo-config-renderer": "^1.0.3",
"mapeo-config-renderer": "^1.0.4",
"mapeo-settings-builder": "^3.4.1",
"mime": "^3.0.0",
"next": "13.4.19",
Expand Down
27 changes: 22 additions & 5 deletions pages/api/upload/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ interface ResponseData {
id: string | null;
}

const defaultConfigUrl = "https://api.github.com/repos/digidem/mapeo-default-config/releases/latest"
const backupConfigUrl = `https://github.com/digidem/mapeo-default-config/releases/download/v3.6.1/mapeo-default-settings-v3.6.1.mapeosettings`

const handler = async (
req: NextApiRequest,
res: NextApiResponse<{
Expand All @@ -25,10 +28,26 @@ const handler = async (
) => {
let fileUrl
if (req.method === "GET") {
const configUrl = process.env.DEFAULT_CONFIG_URL
try {
const response = await fetch("https://api.github.com/repos/digidem/mapeo-default-config/releases/latest");
const data = await response.json();
const mapeoSettingsUrl = data.assets.find((asset: any) => asset.name.endsWith(".mapeosettings")).browser_download_url;
let mapeoSettingsUrl
if (configUrl) {
mapeoSettingsUrl = configUrl
} else {
try {
const response = await fetch(defaultConfigUrl);
const data = await response.json({
headers: {
'Authorization': process.env.GITHUB_TOKEN,
}
});
console.log('data', data);
mapeoSettingsUrl = data.assets.find((asset: any) => asset.name.endsWith(".mapeosettings")).browser_download_url;
} catch (err) {
console.error(`Got error when fetching latest default config from ${defaultConfigUrl}:`, err);
mapeoSettingsUrl = backupConfigUrl
}
}
const fileResponse = await fetch(mapeoSettingsUrl);
const buffer = await fileResponse.buffer();
const filename = `/tmp/${crypto.randomBytes(16).toString("hex")}.mapeosettings`;
Expand All @@ -39,7 +58,6 @@ const handler = async (
res.status(500).json({ data: { id: null }, error: "Internal Server Error" });
}
} else if (req.method === "POST") {

try {
const { fields, files } = await parseForm(req);
const file = files.media;
Expand Down Expand Up @@ -83,7 +101,6 @@ const handler = async (
}
};


export const config = {
api: {
bodyParser: false,
Expand Down
2 changes: 1 addition & 1 deletion pages/p.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const Project = () => {
}
}
checkBuild()
}, [id])
}, [id, router])
const reset = () => router.push('/')
const build = async () => {
setIsLoading(true)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7718,10 +7718,10 @@ mapeo-config-deconstructor@^2.0.6:
tar "^6.1.15"
xml2js "^0.6.2"

mapeo-config-renderer@^1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/mapeo-config-renderer/-/mapeo-config-renderer-1.0.3.tgz#8b935be29cbda520652935ec2a19e9a284236851"
integrity sha512-5AodeHVgX1kAyxyuDQYNahSoDHyrL3ytIaN3eSq2WtPyFNhQva/vJ+ZKo3FgYBlzXR0ixxTBUIGvKHfWzJf/8A==
mapeo-config-renderer@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/mapeo-config-renderer/-/mapeo-config-renderer-1.0.4.tgz#db3d8a183cf586a4c2ed9ecf4f635c02b7c04578"
integrity sha512-7Lxk9A2+M+lGVOGog+kzbe637Uxa5yOmEAKhCsjsn0293X9P5Frr0PNp+EixO9zJqApmPE/fnNAhf3q00+YuqA==
dependencies:
"@testing-library/jest-dom" "^5.17.0"
"@testing-library/react" "^13.4.0"
Expand Down

0 comments on commit 31d1989

Please sign in to comment.