Skip to content

Commit

Permalink
chore: bump deno
Browse files Browse the repository at this point in the history
  • Loading branch information
JounQin committed Mar 29, 2023
1 parent 26ee612 commit 4c8f6df
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 139 deletions.
2 changes: 0 additions & 2 deletions .github/FUNDING.yml

This file was deleted.

5 changes: 5 additions & 0 deletions .renovaterc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": [
"@1stg"
]
}
1 change: 1 addition & 0 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
},
"fmt": {
"options": {
"semiColons": false,
"singleQuote": true
}
}
Expand Down
16 changes: 16 additions & 0 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions main.ts
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)
48 changes: 21 additions & 27 deletions mod.ts
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)
}
87 changes: 40 additions & 47 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -1,53 +1,47 @@

<!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;
}
<!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"><h1>
<a id="user-content-app-center" class="anchor" href="#app-center" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>App Center</h1>
}
</style>
</head>
<body>
<article class="markdown-body"><h1><a id="user-content-app-center" class="anchor" aria-hidden="true" href="#app-center"><span aria-hidden="true" class="octicon octicon-link"></span></a>App Center</h1>
<p>Stable link that redirects to unstable <a href="https://appcenter.ms" rel="nofollow">App Center</a> download link
via Deno Deploy.</p>
<h2>
<a id="user-content-usage" class="anchor" href="#usage" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Usage</h2>
<h2><a id="user-content-usage" class="anchor" aria-hidden="true" href="#usage"><span aria-hidden="true" class="octicon octicon-link"></span></a>Usage</h2>
<p><code>https://appcenter.deno.dev/{owner}/{app}/{version}</code></p>
<h2>
<a id="user-content-examples" class="anchor" href="#examples" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>Examples</h2>
<h2><a id="user-content-examples" class="anchor" aria-hidden="true" href="#examples"><span aria-hidden="true" class="octicon octicon-link"></span></a>Examples</h2>
<ol>
<li>
<p><code>ClashX Pro</code>: <a href="https://appcenter.deno.dev/clashx/clashx-pro/1.30.3.2" rel="nofollow">https://appcenter.deno.dev/clashx/clashx-pro/1.30.3.2</a></p>
Expand All @@ -58,13 +52,12 @@ <h2>
<li><a href="https://appcenter.deno.dev/dangercove/timeless/2020.7" rel="nofollow">https://appcenter.deno.dev/dangercove/timeless/2020.7</a></li>
<li><a href="https://appcenter.deno.dev/dangercove/timeless/37" rel="nofollow">https://appcenter.deno.dev/dangercove/timeless/37</a></li>
</ul>
<p><a href="https://user-images.githubusercontent.com/8336744/98822766-30e03500-246c-11eb-8cab-f7c31d196f5a.png" target="_blank" rel="nofollow"><img src="https://user-images.githubusercontent.com/8336744/98822766-30e03500-246c-11eb-8cab-f7c31d196f5a.png" alt="Timeless" style="max-width:100%;"></a></p>
<p><a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/8336744/98822766-30e03500-246c-11eb-8cab-f7c31d196f5a.png"><img src="https://user-images.githubusercontent.com/8336744/98822766-30e03500-246c-11eb-8cab-f7c31d196f5a.png" alt="Timeless" style="max-width: 100%;"></a></p>
</li>
</ol>
<h2>
<a id="user-content-license" class="anchor" href="#license" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>License</h2>
<h2><a id="user-content-license" class="anchor" aria-hidden="true" href="#license"><span aria-hidden="true" class="octicon octicon-link"></span></a>License</h2>
<p><a href="http://opensource.org/licenses/MIT" rel="nofollow">MIT</a> © <a href="https://GitHub.com/JounQin">JounQin</a>@<a href="https://www.1stg.me" rel="nofollow">1stG.me</a></p>
</article>
</body>
</html>
</body>
</html>

111 changes: 52 additions & 59 deletions scripts/build.ts
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>
`,
)
1 change: 0 additions & 1 deletion version.ts

This file was deleted.

0 comments on commit 4c8f6df

Please sign in to comment.