Skip to content

Commit

Permalink
feat: add uploadthing driver (#390)
Browse files Browse the repository at this point in the history
Co-authored-by: Pooya Parsa <pooya@pi0.io>
  • Loading branch information
juliusmarminge and pi0 authored Dec 18, 2024
1 parent ce9685e commit e049ce6
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ VITE_VERCEL_BLOB_READ_WRITE_TOKEN=
VITE_CLOUDFLARE_ACC_ID=
VITE_CLOUDFLARE_KV_NS_ID=
VITE_CLOUDFLARE_TOKEN=

VITE_UPLOADTHING_TOKEN=
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
VITE_CLOUDFLARE_ACC_ID: ${{ secrets.VITE_CLOUDFLARE_ACC_ID }}
VITE_CLOUDFLARE_KV_NS_ID: ${{ secrets.VITE_CLOUDFLARE_KV_NS_ID }}
VITE_CLOUDFLARE_TOKEN: ${{ secrets.VITE_CLOUDFLARE_TOKEN }}
VITE_UPLOADTHING_TOKEN: ${{ secrets.VITE_UPLOADTHING_TOKEN }}
- uses: codecov/codecov-action@v5
- name: nightly release
if: |
Expand Down
38 changes: 38 additions & 0 deletions docs/2.drivers/uploadthing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
icon: qlementine-icons:cloud-16
---

# UploadThing

> Store data using UploadThing.
::note{to="https://uploadthing.com/"}
Learn more about UploadThing.
::

::warning
UploadThing support is currently experimental!
<br>
There is a known issue that same key, if deleted cannot be used again [tracker issue](https://github.com/pingdotgg/uploadthing/issues/948).
::

## Usage

To use, you will need to install `uploadthing` dependency in your project:

:pm-install{name="uploadthing"}

```js
import { createStorage } from "unstorage";
import uploadthingDriver from "unstorage/drivers/uploadthing";

const storage = createStorage({
driver: uploadthingDriver({
// token: "<your token>", // UPLOADTHING_SECRET environment variable will be used if not provided.
}),
});
```

**Options:**

- `token`: Your UploadThing API key. Will be automatically inferred from the `UPLOADTHING_SECRET` environment variable if not provided.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"types-cloudflare-worker": "^1.2.0",
"typescript": "^5.7.2",
"unbuild": "^3.0.1",
"uploadthing": "^7.4.1",
"vite": "^6.0.3",
"vitest": "^2.1.8",
"wrangler": "^3.97.0"
Expand All @@ -121,7 +122,8 @@
"aws4fetch": "^1.0.20",
"db0": ">=0.2.1",
"idb-keyval": "^6.2.1",
"ioredis": "^5.4.1"
"ioredis": "^5.4.1",
"uploadthing": "^7.4.1"
},
"peerDependenciesMeta": {
"@azure/app-configuration": {
Expand Down Expand Up @@ -174,6 +176,9 @@
},
"ioredis": {
"optional": true
},
"uploadthing": {
"optional": true
}
},
"packageManager": "pnpm@9.15.0"
Expand Down
100 changes: 100 additions & 0 deletions pnpm-lock.yaml

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

5 changes: 4 additions & 1 deletion src/_drivers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ import type { PlanetscaleDriverOptions as PlanetscaleOptions } from "unstorage/d
import type { RedisOptions as RedisOptions } from "unstorage/drivers/redis";
import type { S3DriverOptions as S3Options } from "unstorage/drivers/s3";
import type { SessionStorageOptions as SessionStorageOptions } from "unstorage/drivers/session-storage";
import type { UploadThingOptions as UploadthingOptions } from "unstorage/drivers/uploadthing";
import type { UpstashOptions as UpstashOptions } from "unstorage/drivers/upstash";
import type { VercelBlobOptions as VercelBlobOptions } from "unstorage/drivers/vercel-blob";
import type { VercelKVOptions as VercelKVOptions } from "unstorage/drivers/vercel-kv";

export type BuiltinDriverName = "azure-app-configuration" | "azureAppConfiguration" | "azure-cosmos" | "azureCosmos" | "azure-key-vault" | "azureKeyVault" | "azure-storage-blob" | "azureStorageBlob" | "azure-storage-table" | "azureStorageTable" | "capacitor-preferences" | "capacitorPreferences" | "cloudflare-kv-binding" | "cloudflareKVBinding" | "cloudflare-kv-http" | "cloudflareKVHttp" | "cloudflare-r2-binding" | "cloudflareR2Binding" | "db0" | "deno-kv-node" | "denoKVNode" | "deno-kv" | "denoKV" | "fs-lite" | "fsLite" | "fs" | "github" | "http" | "indexedb" | "localstorage" | "lru-cache" | "lruCache" | "memory" | "mongodb" | "netlify-blobs" | "netlifyBlobs" | "null" | "overlay" | "planetscale" | "redis" | "s3" | "session-storage" | "sessionStorage" | "upstash" | "vercel-blob" | "vercelBlob" | "vercel-kv" | "vercelKV";
export type BuiltinDriverName = "azure-app-configuration" | "azureAppConfiguration" | "azure-cosmos" | "azureCosmos" | "azure-key-vault" | "azureKeyVault" | "azure-storage-blob" | "azureStorageBlob" | "azure-storage-table" | "azureStorageTable" | "capacitor-preferences" | "capacitorPreferences" | "cloudflare-kv-binding" | "cloudflareKVBinding" | "cloudflare-kv-http" | "cloudflareKVHttp" | "cloudflare-r2-binding" | "cloudflareR2Binding" | "db0" | "deno-kv-node" | "denoKVNode" | "deno-kv" | "denoKV" | "fs-lite" | "fsLite" | "fs" | "github" | "http" | "indexedb" | "localstorage" | "lru-cache" | "lruCache" | "memory" | "mongodb" | "netlify-blobs" | "netlifyBlobs" | "null" | "overlay" | "planetscale" | "redis" | "s3" | "session-storage" | "sessionStorage" | "uploadthing" | "upstash" | "vercel-blob" | "vercelBlob" | "vercel-kv" | "vercelKV";

export type BuiltinDriverOptions = {
"azure-app-configuration": AzureAppConfigurationOptions;
Expand Down Expand Up @@ -75,6 +76,7 @@ export type BuiltinDriverOptions = {
"s3": S3Options;
"session-storage": SessionStorageOptions;
"sessionStorage": SessionStorageOptions;
"uploadthing": UploadthingOptions;
"upstash": UpstashOptions;
"vercel-blob": VercelBlobOptions;
"vercelBlob": VercelBlobOptions;
Expand Down Expand Up @@ -126,6 +128,7 @@ export const builtinDrivers = {
"s3": "unstorage/drivers/s3",
"session-storage": "unstorage/drivers/session-storage",
"sessionStorage": "unstorage/drivers/session-storage",
"uploadthing": "unstorage/drivers/uploadthing",
"upstash": "unstorage/drivers/upstash",
"vercel-blob": "unstorage/drivers/vercel-blob",
"vercelBlob": "unstorage/drivers/vercel-blob",
Expand Down
Loading

0 comments on commit e049ce6

Please sign in to comment.