Skip to content

Commit

Permalink
feat: production ready app
Browse files Browse the repository at this point in the history
  • Loading branch information
ful1e5 committed Nov 10, 2023
1 parent 1735fc8 commit 2930c1f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 19 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"next-dev": "next dev",
"dev": "concurrently \"yarn next-dev\" \"yarn flask-dev\"",
"prebuild": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > src/version.ts",
"postinstall": "prisma generate",
"build": "next build",
"start": "next start",
"lint": "next lint"
Expand Down
2 changes: 1 addition & 1 deletion src/app/(home)/studio/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useEffect, useState } from 'react';
import { useSession } from 'next-auth/react';

import { TYPES, PREBUILT_COLORS, SIZES } from '@root/configs';
import { useLocalStorage as useStorage } from '@hooks/useLocalStorage';
import { useSecureStorage as useStorage } from '@hooks/useSecureStorage';

import { TypePicker } from '@components/TypePicker';
import { SizePicker } from '@components/SizePicker';
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { genAccessToken } from '@utils/auth/token';
import { DB_SEEDS } from '@root/configs';
import { Role } from '@prisma/client';

export const authOptions: AuthOptions = {
const authOptions: AuthOptions = {
providers: [
GithubProvider({
clientId: process.env.GITHUB_ID,
Expand Down
4 changes: 2 additions & 2 deletions src/components/Cursors/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const Cursors: React.FC<Props> = (props) => {
}
}, [isLoading, isValidating, props, res]);

if (isLoading || isValidating) return <Loading />;
if (isLoading) return <Loading />;

if (!res) return <Timeout />;

Expand All @@ -56,7 +56,7 @@ export const Cursors: React.FC<Props> = (props) => {
<div className='grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-6'>
{svgs.map((e) => (
<Card
key={`${e.ids}-${e.name}-${props.type}`}
key={e.id}
delay={props.delay}
color={props.color}
svg={e}
Expand Down
18 changes: 12 additions & 6 deletions src/hooks/useLocalStorage.tsx → src/hooks/useSecureStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,29 @@ import ls from 'localstorage-slim';

ls.config.encrypt = true;

export function useLocalStorage<T>(
export function useSecureStorage<T>(
key: string,
initialValue: T
): [T, React.Dispatch<T>] {
key = `bibata.${key}`;

const get = () => {
const d: T = ls.get(key) || initialValue;
return d;
try {
const d: T = ls.get(key) || initialValue;
return d;
} catch {
return initialValue;
}
};

const [value, setValue] = useState<T>(() => get());

useEffect(() => {
setValue(get());
}, [localStorage]); // eslint-disable-line react-hooks/exhaustive-deps
setValue(() => get());
}, [key, initialValue]); // eslint-disable-line react-hooks/exhaustive-deps

useEffect(() => {
ls.set(key, value);
ls.set(key, value, { encrypt: true });
}, [key, value]);

return [value, setValue];
Expand Down
3 changes: 2 additions & 1 deletion src/utils/sponsor/get-count.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { DownloadCounts } from 'bibata/misc';

export const getDownloadCounts = async (token?: string) => {
let headers = undefined;
// eslint-disable-next-line no-undef
let headers: HeadersInit | undefined = undefined;
if (token) {
headers = {
Authorization: `Bearer ${token}`
Expand Down
10 changes: 2 additions & 8 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
{
"crons": [
{
"path": "/api/cron/svg",
"schedule": "0 1 * * *"
}
]
}
{}

0 comments on commit 2930c1f

Please sign in to comment.