Skip to content

Commit

Permalink
Merge pull request #4 from besscroft/dev
Browse files Browse the repository at this point in the history
v0.5.1
  • Loading branch information
besscroft authored May 2, 2024
2 parents 55b4aff + 51f6e78 commit 4464aa5
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 43 deletions.
48 changes: 41 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,53 @@ PicImpact

> 当前为预览版本,会逐步稳定下来,在设计阶段已经尽可能保证后续开发的扩展和兼容性。
你可以点击下面的按钮来一键部署到 Vercel,也可以 Fork 项目后手动部署到任何支持的平台。
你可以点击下面的按钮来一键部署到 Vercel,然后将 `Build Command``pnpm run build:vercel`也可以 Fork 项目后手动部署到任何支持的平台。

<a href="https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fbesscroft%2FPicImpact&env=DATABASE_URL,AUTH_SECRET"><img src="https://vercel.com/button" alt="Deploy with Vercel"/></a>

| Key | 备注 |
|------------------|-------------------------------------------------------------------------------------------|
| DATABASE_URL | Postgre 数据库 url,如:postgres://账号:密码@aws-0-ap-northeast-1.pooler.supabase.com:5432/postgres |
| AUTH_SECRET | 权限机密,你可以执行 npx auth secret 生成一个,反正是随机的字符串就行 |
| Key | 备注 |
|--------------|-------------------------------------------------------------------------------------------|
| DATABASE_URL | Postgre 数据库 url,如:postgres://账号:密码@aws-0-ap-northeast-1.pooler.supabase.com:5432/postgres |
| AUTH_SECRET | 权限机密,你可以执行 npx auth secret 生成一个,反正是随机的字符串就行 |

> 部署就是这么简单,只需要您准备一个干净的数据库就行!
>
> 不过,不支持 ALL Edge 运行时,毕竟 Vercel 就只给了 Edge 100M 内存,太小了...当然,Node.js 运行时是完美支持的~
### 文档
### 存储配置

部署和使用有疑问?没关系,您可以看[文档](https://pic-docs.besscroft.com)
暂时提供了 AWS S3 API、Cloudflare R2、AList API 支持,您在部署成功后,可以去 `设置` -> `存储` 进行管理。

我比较推荐 Cloudflare R2,算是很良心的了,流量免费。

- AWS S3 配置

| Key | 备注 |
|------------------|--------------------------------------------------------------|
| accesskey_id | 阿里 OSS / AWS S3 AccessKey_ID |
| accesskey_secret | 阿里 OSS / AWS S3 AccessKey_Secret |
| region | 阿里 OSS / AWS S3 Region 地域,如:oss-cn-hongkong |
| endpoint | 阿里 OSS / AWS S3 Endpoint 地域节点,如:oss-cn-hongkong.aliyuncs.com |
| bucket | 阿里 OSS / AWS S3 Bucket 存储桶名称,如:picimpact |
| storage_folder | 存储文件夹(S3),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径 |

- Cloudflare R2 配置

| Key | 备注 |
|---------------------|--------------------------------------------------------------------------|
| r2_accesskey_id | Cloudflare AccessKey_ID |
| r2_accesskey_secret | Cloudflare AccessKey_Secret |
| r2_endpoint | Cloudflare Endpoint 地域节点,如:https://<ACCOUNT_ID>.r2.cloudflarestorage.com |
| r2_bucket | Cloudflare Bucket 存储桶名称,如:picimpact |
| r2_storage_folder | 存储文件夹(Cloudflare R2),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径 |
| r2_public_domain | Cloudflare R2 自定义域(公开访问) |

- AList API 配置

| Key | 备注 |
|-------------|----------------------------------------|
| alist_token | alist 令牌 |
| alist_url | AList 地址,如:https://alist.besscroft.com |

### 本地开发

Expand Down
9 changes: 0 additions & 9 deletions app/admin/settings/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ export default function About() {
<span>摄影佬专用⌈相片集⌋,基于 Next.js 开发</span>
<Divider className="my-4" />
<div className="flex flex-col w-full">
<Link
className="flex items-center w-full p-2 hover:bg-slate-100"
href="https://pic-docs.besscroft.com/"
target="_blank"
>
<BookOpenCheck />
<span className="flex-1 px-2">文档</span>
<ExternalLink />
</Link>
<Link
className="flex items-center w-full p-2 hover:bg-slate-100"
href="https://github.com/besscroft/PicImpact"
Expand Down
2 changes: 0 additions & 2 deletions components/admin/dashboard/TagTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ export default function TagTable(props: Readonly<HandleProps>) {

const { data } = useSWRHydrated(props)

console.log(data)

return (
<>
<Card isBlurred shadow="sm" className="h-48">
Expand Down
3 changes: 0 additions & 3 deletions components/admin/upload/FileUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ export default function FileUpload() {
multiple: false,
maxCount: 1,
customRequest: (file) => onRequestUpload(file),
onChange: (event) => {
console.log(event)
},
beforeUpload: async (file) => await onBeforeUpload(file),
onRemove: (file) => {
setStorageSelect(false)
Expand Down
21 changes: 0 additions & 21 deletions doc/sql/data.sql

This file was deleted.

40 changes: 40 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { PrismaClient } from '@prisma/client'

export async function register() {
try {
if (process.env.NEXT_RUNTIME === 'edge') {
return
}
const prisma = new PrismaClient()
if (prisma) {
await prisma.$transaction(async (tx) => {
await tx.configs.createMany({
data: [
{ config_key: 'accesskey_id', config_value: '', detail: '阿里 OSS / AWS S3 AccessKey_ID' },
{ config_key: 'accesskey_secret', config_value: '', detail: '阿里 OSS / AWS S3 AccessKey_Secret' },
{ config_key: 'region', config_value: '', detail: '阿里 OSS / AWS S3 Region 地域,如:oss-cn-hongkong' },
{ config_key: 'endpoint', config_value: '', detail: '阿里 OSS / AWS S3 Endpoint 地域节点,如:oss-cn-hongkong.aliyuncs.com' },
{ config_key: 'bucket', config_value: '', detail: '阿里 OSS / AWS S3 Bucket 存储桶名称,如:picimpact' },
{ config_key: 'storage_folder', config_value: '', detail: '存储文件夹(S3),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径' },
{ config_key: 'alist_token', config_value: '', detail: 'alist 令牌' },
{ config_key: 'alist_url', config_value: '', detail: 'AList 地址,如:https://alist.besscroft.com' },
{ config_key: 'secret_key', config_value: 'pic-impact', detail: 'SECRET_KEY' },
{ config_key: 'r2_accesskey_id', config_value: '', detail: 'Cloudflare AccessKey_ID' },
{ config_key: 'r2_accesskey_secret', config_value: '', detail: 'Cloudflare AccessKey_Secret' },
{ config_key: 'r2_endpoint', config_value: '', detail: 'Cloudflare Endpoint 地域节点,如:https://<ACCOUNT_ID>.r2.cloudflarestorage.com' },
{ config_key: 'r2_bucket', config_value: '', detail: 'Cloudflare Bucket 存储桶名称,如:picimpact' },
{ config_key: 'r2_storage_folder', config_value: '', detail: '存储文件夹(Cloudflare R2),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径' },
{ config_key: 'r2_public_domain', config_value: '', detail: 'Cloudflare R2 自定义域(公开访问)' },
],
skipDuplicates: true,
})
})
console.log('数据库初始化完毕!')
await prisma.$disconnect()
} else {
console.error('数据库初始化失败,请检查您的连接信息!')
}
} catch (e) {
console.error('初始化数据失败,您可能需要准备干净的数据表,请联系管理员!', e)
}
}
1 change: 1 addition & 0 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
const nextConfig = {
experimental: {
serverComponentsExternalPackages: ['pg'],
instrumentationHook: true,
},
eslint: {
ignoreDuringBuilds: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"private": true,
"author": "Bess Croft <[email protected]>",
"scripts": {
"dev": "next dev",
"dev": "pnpm run prisma:generate && next dev",
"build": "next build",
"build:vercel": "pnpm run prisma:deploy && next build",
"start": "next start",
"lint": "next lint",
"prisma:format": "npx prisma format",
Expand Down
52 changes: 52 additions & 0 deletions server/lib/operate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,56 @@ export async function updateTagShow(id: number, show: number) {
}
})
return resultRow
}

export async function initConfig() {
await db.$transaction(async (tx) => {
await tx.$executeRaw`
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('accesskey_id', '', '阿里 OSS / AWS S3 AccessKey_ID', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('accesskey_secret', '', '阿里 OSS / AWS S3 AccessKey_Secret', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('region', '', '阿里 OSS / AWS S3 Region 地域,如:oss-cn-hongkong', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('endpoint', '', '阿里 OSS / AWS S3 Endpoint 地域节点,如:oss-cn-hongkong.aliyuncs.com', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('bucket', '', '阿里 OSS / AWS S3 Bucket 存储桶名称,如:picimpact', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('storage_folder', '', '存储文件夹(S3),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('alist_token', '', 'alist 令牌 ', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('alist_url', '', 'AList 地址,如:https://alist.example.com', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('secret_key', '', 'SECRET_KEY', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('r2_accesskey_id', '', 'Cloudflare AccessKey_ID', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('r2_accesskey_secret', '', 'Cloudflare AccessKey_Secret', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('r2_endpoint', '', 'Cloudflare Endpoint 地域节点,如:https://<ACCOUNT_ID>.r2.cloudflarestorage.com', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('r2_bucket', '', 'Cloudflare Bucket 存储桶名称,如:picimpact', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('r2_storage_folder', '', '存储文件夹(Cloudflare R2),严格格式,如:picimpact 或 picimpact/images ,填 / 或者不填表示根路径', NOW())
ON CONFLICT (config_key) DO NOTHING;
INSERT INTO "public"."Configs" (config_key, config_value, detail, create_time)
VALUES ('r2_public_domain', '', 'Cloudflare R2 自定义域(公开访问)', NOW())
ON CONFLICT (config_key) DO NOTHING;
`
})
}

0 comments on commit 4464aa5

Please sign in to comment.