Skip to content

Commit 9f5a81d

Browse files
authored
Merge pull request #4 from hey-api/chore/db-write
chore: write to database
2 parents 5966bb2 + c4cbf16 commit 9f5a81d

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

dist/index.js

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/upload.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,35 @@ export async function upload(pathToOpenApi: string): Promise<void> {
1919
}
2020

2121
const fileBody = readFileSync(pathToOpenApi)
22-
const parts = pathToOpenApi.split('/')
22+
23+
const match = pathToOpenApi.match(/\.[0-9a-z]+$/i)
24+
const extension = match ? match[0] : ''
25+
2326
// TODO: replace with unique bucket name
24-
const name = `@hey-api/upload-openapi-spec/${new Date().toISOString()}`
25-
const { error } = await supabase.storage
27+
const fileName = new Date().toISOString() + extension
28+
const org = '@hey-api'
29+
const project = 'upload-openapi-spec'
30+
const filePath = `${org}/${project}/${fileName}`
31+
32+
const uploadResponse = await supabase.storage
2633
.from('openapi-specs')
27-
.upload(name, fileBody, {
34+
.upload(filePath, fileBody, {
2835
cacheControl: '3600',
2936
upsert: false
3037
})
3138

32-
if (error) {
33-
throw new Error(error.message)
39+
if (uploadResponse.error) {
40+
throw new Error(uploadResponse.error.message)
41+
}
42+
43+
const insertResponse = await supabase.from('openapi-specs').insert({
44+
org,
45+
path: filePath,
46+
project
47+
})
48+
49+
if (insertResponse.error) {
50+
throw new Error(insertResponse.error.message)
3451
}
3552

3653
resolve()

0 commit comments

Comments
 (0)