-
-
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
Showing
9 changed files
with
138 additions
and
139 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,5 @@ | ||
{ | ||
"extends": [ | ||
"@1stg" | ||
] | ||
} |
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 |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
}, | ||
"fmt": { | ||
"options": { | ||
"semiColons": false, | ||
"singleQuote": true | ||
} | ||
} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { serve } from 'https://deno.land/std@0.137.0/http/server.ts'; | ||
import { serve } from 'https://deno.land/std@0.181.0/http/server.ts' | ||
|
||
import { appcenter } from './mod.ts'; | ||
import { appcenter } from './mod.ts' | ||
|
||
serve(appcenter); | ||
serve(appcenter) |
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 |
---|---|---|
@@ -1,74 +1,68 @@ | ||
export interface ReleaseInfo { | ||
id: string; | ||
version: string; | ||
short_version: string; | ||
id: string | ||
version: string | ||
short_version: string | ||
} | ||
|
||
export interface DownloadInfo { | ||
download_url: string; | ||
download_url: string | ||
} | ||
|
||
export const REDIRECT = 302; | ||
export const NOT_FOUND = 404; | ||
const NOT_FOUND = 404 | ||
|
||
export async function appcenter(req: Request): Promise<Response> { | ||
let url = new URL(req.url).pathname; | ||
let url = new URL(req.url).pathname | ||
|
||
if (!url || url === '/') { | ||
url = '/index.html'; | ||
url = '/index.html' | ||
} | ||
|
||
if (/\.[a-z]+[a-z\d]*$/.test(url)) { | ||
return new Response(await Deno.readFile(`./public${url}`)); | ||
return new Response(await Deno.readFile(`./public${url}`)) | ||
} | ||
|
||
const matched = /\/([\w-]+)\/([\w-]+)\/([.\w]+)/.exec(url); | ||
const matched = /\/([\w-]+)\/([\w-]+)\/([.\w]+)/.exec(url) | ||
|
||
if (!matched) { | ||
return new Response('Not Found', { | ||
status: NOT_FOUND, | ||
}); | ||
}) | ||
} | ||
|
||
const [, owner, app, version] = matched; | ||
const [, owner, app, version] = matched | ||
|
||
const releasesUrl = | ||
`https://install.appcenter.ms/api/v0.1/apps/${owner}/${app}/distribution_groups/public/public_releases`; | ||
`https://install.appcenter.ms/api/v0.1/apps/${owner}/${app}/distribution_groups/public/public_releases` | ||
|
||
console.log(`Fetching ${releasesUrl}`); | ||
console.log(`Fetching ${releasesUrl}`) | ||
|
||
const releases: ReleaseInfo[] = await fetch(releasesUrl).then((res) => | ||
res.ok ? res.json() : [] | ||
); | ||
) | ||
|
||
const found = releases.find( | ||
(it) => it.version === version || it.short_version === version, | ||
); | ||
) | ||
|
||
if (!found) { | ||
return new Response( | ||
`No matched version ${version} found for ${owner}/${app}`, | ||
{ | ||
status: NOT_FOUND, | ||
}, | ||
); | ||
) | ||
} | ||
|
||
const releaseUrl = | ||
`https://install.appcenter.ms/api/v0.1/apps/${owner}/${app}/distribution_groups/public/releases/${found.id}`; | ||
`https://install.appcenter.ms/api/v0.1/apps/${owner}/${app}/distribution_groups/public/releases/${found.id}` | ||
|
||
console.log(`Fetching ${releaseUrl}`); | ||
console.log(`Fetching ${releaseUrl}`) | ||
|
||
const { download_url: downloadUrl }: DownloadInfo = await fetch( | ||
releaseUrl, | ||
).then((res) => res.json()); | ||
).then((res) => res.json()) | ||
|
||
console.log(`Redirect to ${downloadUrl}`); | ||
console.log(`Redirect to ${downloadUrl}`) | ||
|
||
return new Response(null, { | ||
status: REDIRECT, | ||
headers: { | ||
Location: downloadUrl, | ||
}, | ||
}); | ||
return Response.redirect(downloadUrl) | ||
} |
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 |
---|---|---|
@@ -1,66 +1,59 @@ | ||
export const build = async () => { | ||
/** | ||
* @link https://github.com/sindresorhus/github-markdown-css | ||
*/ | ||
const text = await Deno.readTextFile('README.md'); | ||
/** | ||
* @link https://github.com/sindresorhus/github-markdown-css | ||
*/ | ||
const text = await Deno.readTextFile('README.md') | ||
|
||
const content = await fetch('https://api.github.com/markdown', { | ||
method: 'POST', | ||
body: JSON.stringify({ text }), | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
Authorization: `Bearer ${Deno.env.get('GITHUB_TOKEN')}`, | ||
}, | ||
}).then((res) => res.text()); | ||
const content = await fetch('https://api.github.com/markdown', { | ||
method: 'POST', | ||
body: JSON.stringify({ text }), | ||
headers: { | ||
Accept: 'application/vnd.github.v3+json', | ||
Authorization: `Bearer ${Deno.env.get('GITHUB_TOKEN')}`, | ||
}, | ||
}).then((res) => res.text()) | ||
|
||
await Deno.writeTextFile( | ||
'public/index.html', | ||
/* HTML */ ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta | ||
name="viewport" | ||
content="width=device-width, initial-scale=1.0" | ||
/> | ||
<title>App Center</title> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.1.0/github-markdown.min.css" | ||
/> | ||
<style> | ||
@media (prefers-color-scheme: dark) { | ||
:root { | ||
background-color: #0d1117; | ||
} | ||
await Deno.writeTextFile( | ||
'public/index.html', | ||
/* HTML */ ` | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>App Center</title> | ||
<link | ||
rel="stylesheet" | ||
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.2.0/github-markdown.min.css" | ||
/> | ||
<style> | ||
@media (prefers-color-scheme: dark) { | ||
:root { | ||
background-color: #0d1117; | ||
} | ||
} | ||
body { | ||
margin: 0; | ||
} | ||
body { | ||
margin: 0; | ||
} | ||
.markdown-body { | ||
box-sizing: border-box; | ||
min-width: 200px; | ||
max-width: 980px; | ||
margin: 0 auto; | ||
padding: 45px; | ||
} | ||
.markdown-body { | ||
box-sizing: border-box; | ||
min-width: 200px; | ||
max-width: 980px; | ||
margin: 0 auto; | ||
padding: 45px; | ||
} | ||
@media (max-width: 767px) { | ||
.markdown-body { | ||
padding: 15px; | ||
} | ||
@media (max-width: 767px) { | ||
.markdown-body { | ||
padding: 15px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<article class="markdown-body">${content}</article> | ||
</body> | ||
</html> | ||
`, | ||
); | ||
}; | ||
|
||
build().catch(console.error); | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<article class="markdown-body">${content}</article> | ||
</body> | ||
</html> | ||
`, | ||
) |
This file was deleted.
Oops, something went wrong.