File tree Expand file tree Collapse file tree 7 files changed +96
-3
lines changed
Expand file tree Collapse file tree 7 files changed +96
-3
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,6 @@ node_modules
66.vercel_build_output
77cli /dist /prebuild.mjs
88cli /dist
9- .svelte-kit
9+ .svelte-kit
10+
11+ .env
Original file line number Diff line number Diff line change 2222 "@sveltejs/kit" : " ^1.0.0-next.138" ,
2323 "@types/fs-extra" : " ^9.0.9" ,
2424 "@types/js-search" : " ^1.4.0" ,
25+ "@types/redis" : " ^2.8.31" ,
2526 "autoprefixer" : " ^10.2.5" ,
2627 "esbuild" : " ^0.12.0" ,
2728 "eslint" : " ^7.25.0" ,
4344 "@nick-mazuk/ui-svelte" : " 0.29.6" ,
4445 "@sveltejs/adapter-static" : " ^1.0.0-next.13" ,
4546 "date-fns" : " ^2.23.0" ,
46- "js-search" : " ^2.0.0"
47+ "js-search" : " ^2.0.0" ,
48+ "redis" : " ^3.1.2"
4749 }
4850}
Original file line number Diff line number Diff line change 1616
1717 const handleDownload = async () => {
1818 isDownloading = true
19+ fetch (' /api/download-script' , {
20+ method: ' POST' ,
21+ body: JSON .stringify ({
22+ author: data .author .name ,
23+ scriptName: data .fileName ,
24+ }),
25+ })
1926 const response = await fetch (
2027 ` https://raw.githubusercontent.com/Nick-Mazuk/jw-lua-scripts/master/dist/${data .fileName } `
2128 )
Original file line number Diff line number Diff line change 1+ import { promisify } from 'util'
2+
3+ import type { RequestHandler } from '@sveltejs/kit'
4+ import { createClient } from 'redis'
5+
6+ import { dev } from '$app/env'
7+
8+ export const post : RequestHandler = async ( { rawBody } ) => {
9+ const body = JSON . parse ( rawBody . toString ( ) )
10+
11+ const { scriptName, author } = body
12+
13+ if ( typeof scriptName !== 'string' || typeof author !== 'string' )
14+ return { status : 400 , body : { } }
15+
16+ if ( dev ) return { body : { } }
17+
18+ const client = createClient ( {
19+ host : import . meta. env . VITE_REDIS_ENDPOINT ,
20+ port : import . meta. env . VITE_REDIS_PORT ,
21+ password : import . meta. env . VITE_REDIS_PASSWORD ,
22+ tls : { } ,
23+ } )
24+
25+ const increment = promisify ( client . incr ) . bind ( client )
26+
27+ await Promise . all ( [
28+ increment ( `downloads:${ scriptName } ` ) ,
29+ increment ( `downloads:${ author } ` ) ,
30+ increment ( 'downloads' ) ,
31+ ] )
32+
33+ client . quit ( )
34+
35+ return { body : { } }
36+ }
Original file line number Diff line number Diff line change 22 "compilerOptions" : {
33 "moduleResolution" : " node" ,
44 "target" : " es2018" ,
5+ "module" : " ESNext" ,
56 "importsNotUsedAsValues" : " error" ,
67 "isolatedModules" : true ,
78 "sourceMap" : true ,
Original file line number Diff line number Diff line change 1- declare module 'stork-search'
1+ interface ImportMetaEnv {
2+ VITE_REDIS_ENDPOINT : string
3+ VITE_REDIS_PORT : number
4+ VITE_REDIS_PASSWORD : string
5+ }
You can’t perform that action at this time.
0 commit comments