Skip to content

Commit

Permalink
feat: add console page
Browse files Browse the repository at this point in the history
  • Loading branch information
loyep committed Oct 19, 2024
1 parent ee9b8ef commit ff2ed12
Show file tree
Hide file tree
Showing 26 changed files with 1,221 additions and 663 deletions.
8 changes: 4 additions & 4 deletions apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@langchain/anthropic": "^0.3.5",
"@langchain/community": "^0.3.6",
"@langchain/core": "^0.3.13",
"@langchain/openai": "^0.3.10",
"@langchain/openai": "^0.3.11",
"@nest-lab/throttler-storage-redis": "^1.0.0",
"@nestjs/axios": "^3.0.3",
"@nestjs/bullmq": "^10.2.1",
Expand All @@ -50,10 +50,10 @@
"@nestjs/throttler": "^6.2.1",
"@niceai/cache": "workspace:*",
"axios": "^1.7.7",
"bullmq": "^5.21.0",
"bullmq": "^5.21.1",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"drizzle-orm": "^0.35.1",
"drizzle-orm": "^0.35.2",
"drizzle-zod": "^0.5.1",
"fastify": "^4.28.1",
"helmet": "^7.2.0",
Expand All @@ -77,7 +77,7 @@
"@niceai/cli": "workspace:*",
"@swc/cli": "^0.4.1-nightly.20240914",
"@swc/core": "^1.7.36",
"@types/lodash": "^4.17.10",
"@types/lodash": "^4.17.11",
"@types/request-ip": "^0.0.41",
"cross-env": "^7.0.3",
"drizzle-kit": "^0.26.2",
Expand Down
104 changes: 10 additions & 94 deletions apps/api/src/cache/cache.service.ts
Original file line number Diff line number Diff line change
@@ -1,105 +1,21 @@
import { Injectable, OnModuleDestroy, OnModuleInit } from '@nestjs/common';
import type { Redis } from 'ioredis';
import { CacheClosure, CacheStore } from '@niceai/cache';
import { CacheService as CacheStoreService } from '@niceai/cache/node';
import { type Redis } from 'ioredis';

@Injectable()
export class CacheService implements OnModuleDestroy, OnModuleInit {
protected store: CacheStore;

protected readonly cachePrefix: string;

export class CacheService
extends CacheStoreService
implements OnModuleInit, OnModuleDestroy
{
constructor(redis: Redis, opts: { prefix?: string } = {}) {
this.store = new CacheStore(redis, opts);
super(redis, opts);
}

async onModuleInit() {
await this.store.connect();
}

getPrefix() {
return this.store.getPrefix();
}

async set(key: string, value: unknown, seconds?: number) {
return this.store.set(key, value, seconds);
}

putMany(values: Record<string, unknown>, seconds?: number) {
return this.store.putMany(values, seconds);
}

async rememberForever<T>(key: string, fn: () => Promise<T>): Promise<T> {
return this.store.rememberForever<T>(key, fn);
}

async remember<T>(
key: string,
fn?: CacheClosure<T>,
seconds?: number,
): Promise<T | null> {
const now = Date.now();
const res = await this.store.remember(key, fn, seconds);
console.log(Date.now() - now);
return res;
}

async increment(key: string, value = 1) {
return this.store.increment(key, value);
}

async decrement(key: string, value = 1) {
return this.store.decrement(key, value);
}

async forever(key: string, value: unknown) {
return this.store.forever(key, value);
}

async forget(key: string): Promise<boolean> {
return this.store.forget(key);
}

async get<T>(key: string, defaultVal?: T): Promise<T | null> {
return this.store.get<T>(key, defaultVal);
}

async del(key: string): Promise<boolean> {
return this.store.delete(key);
}

async deleteMultiple(keys: string[]): Promise<boolean> {
return this.store.deleteMultiple(keys);
}

async has(key: string): Promise<boolean> {
return this.store.has(key);
}

async pull<T>(key: string) {
return this.store.pull<T>(key);
}

async put<T>(key: string, value: T, seconds?: number) {
return this.store.put(key, value, seconds);
}

async ttl(key: string): Promise<number | null> {
return this.store.ttl(key);
}

async flush(): Promise<boolean> {
return this.store.flush();
}

async getMultiple(keys: string[]): Promise<any> {
return this.store.getMultiple(keys);
}

async add<T>(key: string, value: T, seconds?: number) {
return this.store.add<T>(key, value, seconds);
await this.cache.connect();
}

onModuleDestroy(): void {
this.store.disconnect();
onModuleDestroy() {
this.cache.disconnect();
}
}
3 changes: 3 additions & 0 deletions apps/web/app/components/auth/login-form.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const LoginForm = () => {
return <div>LoginForm</div>;
};
8 changes: 7 additions & 1 deletion apps/web/app/routes/console+/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Outlet } from '@remix-run/react';
import { Avatar } from 'antd';

export const ROUTE_PATH = '/console' as const;

export default function AuthLayout() {
return <Outlet />;
return (
<div>
当前用户:<Avatar className="bg-blue-500">N</Avatar>
<Outlet />
</div>
);
}
18 changes: 18 additions & 0 deletions apps/web/app/routes/console+/apps+/_index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type { MetaFunction } from '@vercel/remix';
import { Button } from 'antd';

export const meta: MetaFunction = () => {
return [
{ title: 'New Remix App' },
{ name: 'description', content: 'Welcome to Remix!' },
];
};

export default function Login() {
return (
<div>
<h1>Console</h1>
<Button>Login</Button>
</div>
);
}
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@remix-run/dev": "^2.13.1",
"@types/cookie": "^0.6.0",
"@types/js-cookie": "^3.0.6",
"@types/lodash": "^4.17.10",
"@types/lodash": "^4.17.11",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"autoprefixer": "^10.4.20",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
"@changesets/cli": "^2.27.9",
"@esbuild-plugins/node-resolve": "^0.2.2",
"@niceai/cli": "workspace:*",
"@types/node": "^20.16.12",
"@types/node": "^20.16.13",
"@vitest/coverage-v8": "^2.1.3",
"dotenv": "^16.4.5",
"dotenv-cli": "^7.4.2",
"niceai-scripts": "workspace:*",
"rimraf": "^6.0.1",
"tsup": "^8.3.0",
"tsx": "^4.19.1",
"turbo": "^2.1.3",
"turbo": "^2.2.0",
"typescript": "^5.6.3",
"vitest": "^2.1.3"
},
Expand Down
11 changes: 9 additions & 2 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.mjs",
"require": "./dist/node.cjs"
}
},
"files": ["dist"],
"files": [
"dist"
],
"repository": {
"url": "https://github.com/niceaidev/niceai",
"type": "git",
Expand All @@ -32,7 +39,7 @@
"lodash": "^4.17.21"
},
"devDependencies": {
"@types/lodash": "^4.17.10",
"@types/lodash": "^4.17.11",
"superjson": "^2.2.1",
"typescript": "^5.6.3"
},
Expand Down
Loading

0 comments on commit ff2ed12

Please sign in to comment.