Skip to content

Commit

Permalink
Merge branch 'main' into handle-callback-failed
Browse files Browse the repository at this point in the history
  • Loading branch information
juliusmarminge authored Jan 3, 2025
2 parents 2ee0d0c + 36b0df6 commit dd7eba0
Show file tree
Hide file tree
Showing 101 changed files with 5,233 additions and 2,910 deletions.
10 changes: 10 additions & 0 deletions .changeset/nice-penguins-grow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"uploadthing": minor
"@uploadthing/svelte": minor
"@uploadthing/react": minor
"@uploadthing/solid": minor
"@uploadthing/expo": minor
"@uploadthing/vue": minor
---

feat: allow custom fetch override
7 changes: 6 additions & 1 deletion .github/release-canary.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ async function version() {

// Update dependencies
for (const dep in pkg.dependencies) {
if (versions[dep]) {
if (versions[dep] && pkg.dependencies[dep].startsWith("workspace:")) {
pkg.dependencies[dep] = versions[dep];
}
}
for (const dep in pkg.peerDependencies) {
if (versions[dep] && pkg.peerDependencies[dep].startsWith("workspace:")) {
pkg.peerDependencies[dep] = versions[dep];
}
}

const fmt = prettier.format(JSON.stringify(pkg), { filepath: pkgJsonPath });
fs.writeFileSync(pkgJsonPath, fmt);
Expand Down
9 changes: 7 additions & 2 deletions .github/replace-workspace-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ await Promise.all(
const workspacePkg = await Bun.file("package.json").json();
for (const dep in workspacePkg.dependencies) {
if (dep in packageVersions) {
workspacePkg.dependencies[dep] = packageVersions[dep];
if (workspacePkg.dependencies[dep].startsWith("workspace:")) {
workspacePkg.dependencies[dep] = packageVersions[dep];
}
}
}
for (const dep in workspacePkg.peerDependencies) {
if (dep in packageVersions) {
if (
dep in packageVersions &&
workspacePkg.peerDependencies[dep].startsWith("workspace:")
) {
workspacePkg.peerDependencies[dep] = packageVersions[dep];
}
}
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ jobs:

- name: Build
run: pnpm turbo build --filter "./packages/*"

- name: Install Playwright
run: pnpm exec playwright install chromium

- name: Test
run: pnpm run test
env:
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.11
22.12
17 changes: 5 additions & 12 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@mdx-js/react": "^3.0.1",
"@next/mdx": "^14.2.11",
"@scalar/api-reference-react": "^0.3.37",
"@shikijs/transformers": "^1.17.5",
"@sindresorhus/slugify": "^2.1.1",
"@tailwindcss/typography": "^0.5.10",
"@types/mdast": "^4.0.4",
Expand All @@ -29,7 +30,7 @@
"@types/react-highlight-words": "^0.20.0",
"@uploadthing/react": "workspace:*",
"acorn": "^8.12.1",
"autoprefixer": "^10.4.19",
"autoprefixer": "^10.4.20",
"clsx": "^2.1.0",
"fast-glob": "^3.3.2",
"flexsearch": "^0.7.43",
Expand All @@ -49,24 +50,16 @@
"remark-gfm": "^4.0.0",
"remark-mdx": "^3.0.1",
"remark-unwrap-images": "^4.0.0",
"sharp": "0.33.1",
"shiki": "^1.17.5",
"simple-functional-loader": "^1.2.1",
"tailwindcss": "^3.4.1",
"tailwindcss": "^3.4.16",
"typescript": "^5.5.2",
"unified": "^11.0.5",
"unist-util-filter": "^5.0.1",
"unist-util-visit": "^5.0.0",
"uploadthing": "workspace:*",
"zod": "^3.23.8",
"zustand": "^4.3.2"
},
"devDependencies": {
"@shikijs/transformers": "^1.17.5",
"eslint": "^8.57.0",
"eslint-config-next": "^14.2.1",
"prettier": "^3.3.2",
"prettier-plugin-tailwindcss": "^0.6.5",
"sharp": "0.33.1"
},
"packageManager": "pnpm@9.6.0"
}
}
97 changes: 83 additions & 14 deletions docs/src/app/(docs)/uploading-files/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,25 @@ this process easier in the future.
in mind that this adds extra latency to your uploads.
</Note>

<Tabs tabs={["JavaScript", "Python", "PHP", "Go"]}>
<Tabs tabs={["JavaScript", "Python", "PHP", "Go", "Rust"]}>
<Tab>

```ts
import * as Hash from "effect/Hash";
import SQIds, { defaultOptions } from "sqids";

function djb2(s: string) {
const h = 5381;
let i = s.length;
while (i) {
h = (h * 33) ^ s.charCodeAt(--i);
}
return (h & 0xbfffffff) | ((h >>> 1) & 0x40000000);
}

// A simple function to shuffle the alphabet for the Sqids
function shuffle(str: string, seed: string) {
const chars = str.split("");
const seedNum = Hash.string(seed);
const seedNum = djb2(seed);

let temp: string;
let j: number;
Expand All @@ -142,7 +150,7 @@ function generateKey(appId: string, fileSeed: string) {
const alphabet = shuffle(defaultOptions.alphabet, appId);

const encodedAppId = new SQIds({ alphabet, minLength: 12 }).encode([
Math.abs(Hash.string(appId)),
Math.abs(djb2(appId)),
]);

// We use a base64 encoding here to ensure the file seed is url safe, but
Expand All @@ -162,7 +170,7 @@ import base64
from sqids import Sqids
from sqids.constants import DEFAULT_ALPHABET

def hash_string(s: str) -> int:
def djb2(s: str) -> int:
h = 5381
for char in reversed(s):
h = (h * 33) ^ ord(char)
Expand All @@ -179,7 +187,7 @@ def hash_string(s: str) -> int:

def shuffle(string: str, seed: str) -> str:
chars = list(string)
seed_num = hash_string(seed)
seed_num = djb2(seed)

for i in range(len(chars)):
j = int(math.fmod(math.fmod(seed_num, i + 1) + i, len(chars)))
Expand All @@ -192,7 +200,7 @@ def generate_key(file_seed: str, app_id: str) -> str:
alphabet = shuffle(DEFAULT_ALPHABET, app_id)

encoded_app_id = Sqids(alphabet, min_length=12).encode(
[abs(hash_string(app_id))]
[abs(djb2(app_id))]
)

return encoded_app_id + file_seed
Expand All @@ -204,7 +212,7 @@ def generate_key(file_seed: str, app_id: str) -> str:
```php
use Sqids\Sqids;

function hash_string(string $string): int {
function djb2(string $string): int {
$h = 5381;
for ($i = strlen($string) - 1; $i >= 0; $i--) {
$char = $string[$i];
Expand All @@ -224,7 +232,7 @@ function hash_string(string $string): int {

function shuffle_string(string $string, string $seed): string {
$chars = str_split($string);
$seed_num = hash_string($seed);
$seed_num = djb2($seed);

for ($i = 0; $i < count($chars); $i++) {
$j = (($seed_num % ($i + 1)) + $i) % count($chars);
Expand All @@ -239,7 +247,7 @@ function generate_key(string $file_seed, string $appId): string {
$sqids = new Sqids($alphabet, 12);

$encodedAppId = $sqids->encode(
[abs(hash_string($appId))]
[abs(djb2($appId))]
);

return $encodedAppId . base64_encode($file_seed);
Expand All @@ -255,7 +263,7 @@ import (
"github.com/sqids/sqids-go"
)

func hashString(s string) int32 {
func djb2(s string) int32 {
h := int64(5381)
for i := len(s) - 1; i >= 0; i-- {
h = (h * 33) ^ int64(s[i])
Expand All @@ -274,7 +282,7 @@ func hashString(s string) int32 {

func shuffle(input string, seed string) string {
chars := []rune(input)
seedNum := hashString(seed)
seedNum := djb2(seed)

for i := 0; i < len(chars); i++ {
j := (int(seedNum)%(i+1) + i) % len(chars)
Expand All @@ -292,11 +300,67 @@ func generateKey(fileSeed string, appId string) string {
})

encodedAppId, _ := s.Encode(
[]uint64{uint64(math.Abs(float64(hashString(appId))))},
[]uint64{uint64(math.Abs(float64(djb2(appId))))},
)

return encodedAppId + fileSeed
}
```

</Tab>
<Tab>

```rust
fn djb2_hash(s: &str) -> i32 {
let mut h: i64 = 5381;
for &byte in s.as_bytes().iter().rev() {
h = (h * 33) ^ (byte as i64);
// Simulate 32-bit integer overflow
h &= 0xFFFFFFFF;
}
// Convert to signed 32-bit integer with the same bit manipulation
h = (h & 0xBFFFFFFF) | ((h >> 1) & 0x40000000);
if h >= 0x80000000 {
h -= 0x100000000;
}
h as i32
}

fn shuffle(input: &str, seed: &str) -> String {
let mut chars: Vec<char> = input.chars().collect();
let seed_num = djb2_hash(seed);
for i in 0..chars.len() {
let j = ((seed_num % (i as i32 + 1)) + i as i32) as usize % chars.len();
let temp = chars[i];
chars[i] = chars[j];
chars[j] = temp;
}
chars.iter().collect()
}
fn generate_file_key(app_id: String) -> String {
let app_hash = djb2_hash(&app_id);
let alphabet: Vec<char> = shuffle(sqids::DEFAULT_ALPHABET, &app_id).chars().collect();

// https://sqids.org/rust
let sqids = sqids::Sqids::builder()
.alphabet(alphabet)
.min_length(12)
.build()
.expect("Could not create sqid builder");
let encoded_app_id = sqids.encode(&vec![app_hash.abs() as u64]).expect("Could not encode sqid");

// https://github.com/uuid-rs/uuid
let file_seed = uuid::Uuid::new_v4().to_string();

// We use a base64 encoding here to ensure the file seed is url safe, but
// you can do this however you want
// https://github.com/marshallpierce/rust-base64
use base64::prelude::*;
let encoded_file_seed = BASE64_URL_SAFE.encode(file_seed.as_bytes());

format!("{}{}", encoded_app_id, encoded_file_seed)
}

```

</Tab>
Expand Down Expand Up @@ -334,10 +398,15 @@ const url = new URL(
);
url.search = searchParams.toString();

const signature = hmacSha256(url, apiKey);
const signature = `hmac-sha256=${hmacSha256(url, apiKey)}`;
url.searchParams.append("signature", signature);
```

<Note>
Note that the `expires` parameter is measured in milliseconds since the Unix
epoch.
</Note>

<Warning>
The upload will fail if any parameter doesn't match the uploaded file (e.g.
the file is larger than the specified size). Constructing invalid file keys
Expand Down
1 change: 1 addition & 0 deletions docs/src/mdx/rehype.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ function rehypeShiki() {
"diff",
"go",
"php",
"rust",
],
});

Expand Down
4 changes: 2 additions & 2 deletions examples/backend-adapters/client-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
"start": "vite preview"
},
"dependencies": {
"@uploadthing/react": "7.1.3",
"@uploadthing/react": "7.1.5",
"react": "18.3.1",
"react-dom": "18.3.1",
"uploadthing": "7.4.1"
"uploadthing": "7.4.4"
},
"devDependencies": {
"@types/react": "18.3.3",
Expand Down
2 changes: 1 addition & 1 deletion examples/backend-adapters/client-vanilla/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"preview": "vite preview"
},
"dependencies": {
"uploadthing": "7.4.1"
"uploadthing": "7.4.4"
},
"devDependencies": {
"typescript": "^5.5.2",
Expand Down
4 changes: 2 additions & 2 deletions examples/backend-adapters/client-vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@uploadthing/vue": "7.1.3",
"uploadthing": "7.4.1",
"@uploadthing/vue": "7.1.5",
"uploadthing": "7.4.4",
"vue": "^3.4.21"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions examples/backend-adapters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"test": "playwright test"
},
"dependencies": {
"@playwright/test": "1.45.0",
"@uploadthing/react": "7.1.3",
"@playwright/test": "1.49.1",
"@uploadthing/react": "7.1.5",
"concurrently": "^8.2.2",
"typescript": "^5.5.2",
"uploadthing": "7.4.1"
"uploadthing": "7.4.4"
}
}
8 changes: 4 additions & 4 deletions examples/backend-adapters/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
"dev:effect": "NODE_ENV=development PORT=3003 tsx watch src/effect-platform.ts"
},
"dependencies": {
"@effect/platform": "0.70.7",
"@effect/platform-node": "0.65.7",
"@effect/platform": "0.72.0",
"@effect/platform-node": "0.68.0",
"@elysiajs/cors": "^1.1.1",
"@fastify/cors": "^9.0.1",
"@hono/node-server": "^1.8.2",
"@sinclair/typebox": "^0.34.3",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"effect": "3.11.5",
"effect": "3.12.0",
"elysia": "^1.1.16",
"express": "^4.18.2",
"fastify": "^4.26.1",
"h3": "^1.11.1",
"hono": "^4.0.8",
"listhen": "^1.7.2",
"uploadthing": "7.4.1"
"uploadthing": "7.4.4"
},
"devDependencies": {
"@cloudflare/workers-types": "^4.20240620.0",
Expand Down
4 changes: 2 additions & 2 deletions examples/minimal-appdir/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"@uploadthing/react": "7.1.3",
"@uploadthing/react": "7.1.5",
"next": "14.2.11",
"react": "18.3.1",
"react-dom": "18.3.1",
"uploadthing": "7.4.1"
"uploadthing": "7.4.4"
},
"devDependencies": {
"@next/bundle-analyzer": "14.2.3",
Expand Down
Loading

0 comments on commit dd7eba0

Please sign in to comment.