forked from sillsdev/appbuilder-containerapp-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added REST endpoint * rest api POST route * removed redundancy in post method * formatting for lint * removed additional redundancy
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 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,37 @@ | ||
import { db } from '$lib/fbconfig.js'; | ||
import { addDoc, collection } from 'firebase/firestore'; | ||
import { allKeys, initKeys } from '$lib/stores/keys.js'; | ||
import { initPackages } from '$lib/stores/packages.js'; | ||
|
||
export async function POST({ request }) { | ||
await initKeys(); | ||
|
||
let valid = false; | ||
|
||
const bearer = request.headers.get('authorization'); | ||
|
||
allKeys.subscribe((keys) => { | ||
keys.forEach((key) => { | ||
if (bearer.includes(key.key)) { | ||
valid = true; | ||
} | ||
}); | ||
}); | ||
|
||
if (valid) { | ||
const pack = await request.json(); | ||
|
||
const col = collection(db, 'packages'); | ||
|
||
await addDoc(col, { | ||
accepted: '', | ||
...pack | ||
}); | ||
|
||
await initPackages(); | ||
|
||
return new Response(201); | ||
} else { | ||
return new Response(401); | ||
} | ||
} |