Skip to content

Commit 7f5833e

Browse files
committed
chore: update README
1 parent d7a1670 commit 7f5833e

File tree

1 file changed

+95
-8
lines changed

1 file changed

+95
-8
lines changed

README.md

Lines changed: 95 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,101 @@
1-
# Nuxt Todo List on the Edge
1+
# NuxtHub Demo
2+
3+
A demonstration using [Nuxt](https://nuxt.com) as a fullstack framework on the edge.
4+
5+
## Blob
6+
7+
### Upload a blob
8+
9+
```ts
10+
const blob = await useBlob().put('my-file.txt', 'Hello World!', {
11+
contentType: 'text/plain' // optional, will be inferred from the file extension
12+
addRandomSuffix: true // optional, will add a suffix to the filename to avoid collisions
13+
})
14+
/*
15+
{
16+
pathname: 'my-file-12345.txt',
17+
contentType: 'text/plain',
18+
size: 12,
19+
uploadedAt: '2021-08-12T15:00:00.000Z'
20+
}
21+
*/
22+
```
23+
24+
### Usage with file upload
25+
26+
```ts
27+
export default eventHandler(async (event) => {
28+
const form = await readFormData(event)
29+
const file = form.get('file')
30+
31+
return useBlob().put(file.name, file)
32+
})
33+
```
34+
35+
### List blobs
236

3-
A demonstration using [Nuxt](https://nuxt.com) with server-side rendering on the edge, authentication and database querying using SQLite in production.
37+
```ts
38+
// Get a blob object
39+
const { blobs, cursor, hasMore } = await useBlob().list({
40+
limit: 10, // optional, default to 1000
41+
prefix: 'my-dir', // optional, will only list blobs starting with `my-dir`
42+
})
43+
```
44+
45+
#### Pagination
46+
47+
```ts
48+
const blob = useBlob()
49+
let blobs = []
50+
let hasMore = true
51+
let cursor
52+
53+
while (hasMore) {
54+
const result = await blob.list({
55+
cursor,
56+
})
57+
blobs.push(...result.blobs)
58+
hasMore = result.hasMore
59+
cursor = result.cursor
60+
}
61+
```
62+
63+
### Get blob metadata
64+
65+
```ts
66+
const blob = await useBlob().head('my-file.txt')
67+
```
468

5-
## Features
69+
### Delete a blob
670

7-
- [Server-Side Rendering on the Edge](https://nuxt.com/blog/nuxt-on-the-edge)
8-
- Authentication backed-in using [nuxt-auth-utils](https://github.com/Atinux/nuxt-auth-utils)
9-
- Leverage SQLite as database with migrations using [drizzle ORM](https://orm.drizzle.team/)
10-
- User interface made with [Nuxt UI](https://ui.nuxt.com)
11-
- Embed [Drizzle Studio](https://orm.drizzle.team/drizzle-studio/overview/) in the [Nuxt DevTools](https://devtools.nuxt.com)
71+
```ts
72+
await useBlob().delete('my-file.txt')
73+
```
74+
75+
It returns a void response. A delete action is always successful if the blob url exists. A delete action won't throw if the blob url doesn't exists.
76+
77+
### Serve a blob
78+
79+
```ts
80+
// server/routes/[...pathname].get.ts
81+
export default eventHandler(event => {
82+
const pathname = event.context.params.pathname
83+
return useBlob().serve(event, pathname)
84+
})
85+
```
86+
87+
## Key-Value Storage
88+
89+
- useKV() -> process.env.KV binding
90+
- useConfig() -> process.env.KV with `_config` key
91+
92+
- useKV().setItem('public/')
93+
94+
### Get a value
95+
96+
```ts
97+
const value = await useKV().get('my-key')
98+
```
1299

13100
## Live demos
14101

0 commit comments

Comments
 (0)