-
Notifications
You must be signed in to change notification settings - Fork 2
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
f4f13d1
commit 3e1db4f
Showing
13 changed files
with
107 additions
and
37 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Uplo Cloudflare Workers Example | ||
|
||
Cloudflare Workers + Neon Postgres + Drizzle Adapter | ||
|
||
## Requirements | ||
|
||
* [Neon database](https://neon.tech) | ||
|
||
## Usage | ||
|
||
Create `.dev.vars` file: | ||
|
||
```text | ||
AWS_ENDPOINT="" | ||
AWS_BUCKET="" | ||
AWS_ACCESS_KEY_ID="" | ||
AWS_SECRET_ACCESS_KEY="" | ||
DATABASE_URL="" | ||
``` |
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,3 @@ | ||
# Uplo Node Example | ||
|
||
Node + Prisma + Postgres |
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,2 +1,3 @@ | ||
export * from '@uplo/server' | ||
export * from './blobInputs' | ||
export * from '@uplo/server'; | ||
export { default } from '@uplo/server'; | ||
export * from './blobInputs'; |
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,12 +1,19 @@ | ||
export const checksumString = async (content: string) => { | ||
const msgUint8 = new TextEncoder().encode(content); // encode as (utf-8) Uint8Array | ||
export const checksumString = async (content: string | Uint8Array) => { | ||
let msgUint8: Uint8Array; | ||
|
||
if (typeof content === 'string') { | ||
msgUint8 = new TextEncoder().encode(content); // encode as (utf-8) Uint8Array | ||
} else { | ||
msgUint8 = content; | ||
} | ||
|
||
const hashBuffer = await crypto.subtle.digest('MD5', msgUint8); // hash the message | ||
// const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array | ||
// // const hashHex = hashArray | ||
// .map((b) => b.toString(16).padStart(2, '0')) | ||
// .join(''); | ||
|
||
const digest = btoa(String.fromCharCode(...new Uint8Array(hashBuffer))); | ||
const digest = btoa(String.fromCharCode(...new Uint8Array(hashBuffer))); | ||
|
||
return digest; | ||
}; |
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 @@ | ||
function dec2hex (dec: any) { | ||
return dec.toString(16).padStart(2, "0") | ||
function dec2hex(dec: any) { | ||
return dec.toString(16).padStart(2, '0'); | ||
} | ||
|
||
export const generateKey = async (size: number = 32) => { | ||
const arr = new Uint8Array((size || 40) / 2) | ||
globalThis.crypto.getRandomValues(arr) | ||
return Array.from(arr, dec2hex).join('') | ||
} | ||
const arr = new Uint8Array((size || 40) / 2); | ||
globalThis.crypto.getRandomValues(arr); | ||
return Array.from(arr, dec2hex).join(''); | ||
}; |
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,6 +1,10 @@ | ||
import crypto from 'node:crypto'; | ||
|
||
export const checksumString = async (content: string) => { | ||
const buffer = Buffer.from(content, 'utf-8') | ||
export const checksumString = async (content: string | Uint8Array) => { | ||
if (typeof content !== 'string') { | ||
throw new Error('Expected content to be a string'); | ||
} | ||
|
||
const buffer = Buffer.from(content, 'utf-8'); | ||
return crypto.createHash('md5').update(buffer).digest('base64'); | ||
} | ||
}; |
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,12 +1,12 @@ | ||
import { randomBytes } from 'node:crypto'; | ||
|
||
/** | ||
* Returns random key. This is used to generate Blob key. | ||
* | ||
* @param size - Length of the key | ||
* @returns Generated key | ||
* | ||
*/ | ||
* Returns random key. This is used to generate Blob key. | ||
* | ||
* @param size - Length of the key | ||
* @returns Generated key | ||
* | ||
*/ | ||
export const generateKey = async (size: number = 32) => { | ||
return randomBytes(size).toString('hex'); | ||
}; |
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