-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
73acf8f
commit b890958
Showing
7 changed files
with
45 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export { EventEmitter } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { decompress_with as unzlib } from 'npm:@evan/[email protected]/target/zlib/node.mjs' | ||
export { fetchAuto } from 'https://deno.land/x/[email protected]/mod.ts' | ||
export { walk } from 'jsr:@std/[email protected]/walk' | ||
export { join } from 'node:path' | ||
export { Mixin } from 'npm:[email protected]' | ||
export { verify as edverify } from 'npm:@evan/[email protected]/target/ed25519/node.mjs' | ||
export { decodeHex } from 'jsr:@std/[email protected]/hex' | ||
export { encodeBase64 } from 'jsr:@std/[email protected]/base64' | ||
export { readAll } from 'jsr:@std/[email protected]/read_all' |
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
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { encodeBase64 } from '../../deps.ts' | ||
|
||
export const fetchRemote = async ( | ||
url: URL, | ||
onlyData = false | ||
): Promise<string> => { | ||
const resp = await fetch(url) | ||
if (resp.status !== 200) | ||
throw new Error(`Request Failed. Server responsed with code ${resp.status}`) | ||
const contentType = | ||
resp.headers.get('content-type') ?? 'application/octet-stream' | ||
const buff = await resp.arrayBuffer() | ||
const data = encodeBase64(buff) | ||
return onlyData ? data : `data:${contentType};base64,${data}` | ||
} | ||
|
||
export const fetchLocal = async ( | ||
url: string | URL, | ||
onlyData = false | ||
): Promise<string> => { | ||
const file = await Deno.readFile(url) | ||
const data = encodeBase64(file) | ||
const href = typeof url === 'string' ? url : url.href | ||
const contentType = `image/${href.split('.').reverse()[0]}` | ||
return onlyData ? data : `data:${contentType};base64,${data}` | ||
} | ||
|
||
export const fetchAuto = async ( | ||
path: string, | ||
onlyData = false | ||
): Promise<string> => { | ||
try { | ||
const url = new URL(path) | ||
if (url.protocol.startsWith('http')) return await fetchRemote(url, onlyData) | ||
else return await fetchLocal(url, onlyData) | ||
} catch (e) { | ||
return await fetchLocal(path, onlyData) | ||
} | ||
} |