Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

410 base64 blur data 1 #412

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .idea/.gitignore

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/electron-vite-turbo.iml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p align="center">
<a herf="https://rao.pics" target="_blank">
<a href="https://rao.pics" target="_blank">
<img width="196" src="./rao-pics.svg" alt="rao.pics logo"/>
</a>
<h1 align="center">Rao Pics</h1>
Expand All @@ -13,7 +13,7 @@
</div>
</p>

<img src="https://repobeats.axiom.co/api/embed/e9735009c7d58372e055f2875a36283f25a60540.svg" width="100%" />
<img src="https://repobeats.axiom.co/api/embed/e9735009c7d58372e055f2875a36283f25a60540.svg" width="100%" alt="repobeats"/>

## 特点

Expand Down
1 change: 0 additions & 1 deletion apps/electron/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"clean:dist": "git clean -xdf dist",
"dev": "electron-vite dev",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
"postinstall": "electron-builder install-app-deps",
"lint": "eslint .",
"start": "electron-vite preview",
"typecheck": "pnpm typecheck:node && pnpm typecheck:web",
Expand Down
92 changes: 45 additions & 47 deletions apps/electron/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ const caller = router.createCaller({});
const controller = new AbortController();
const { signal } = controller;

// 获取端口
async function initConfig() {
const config = await caller.config.get();

const staticServerPort =
config?.staticServerPort ??
(await getPort({ port: portNumbers(9100, 9300) }));
const themeServerPort =
config?.themeServerPort ??
(await getPort({ port: portNumbers(9301, 9500) }));

return await caller.config.upsert({
staticServerPort,
themeServerPort,
});
}

function createWindow(): void {
// Create the browser window.
const mainWindow = new BrowserWindow({
Expand Down Expand Up @@ -74,57 +91,38 @@ function createWindow(): void {
// Some APIs can only be used after this event occurs.
app
.whenReady()
.then(() => {
.then(async () => {
// Set app user model id for windows
electronApp.setAppUserModelId("com.rao-pics");

Promise.all([caller.library.get(), caller.config.get()])
.then(async (res) => {
const [library, config] = res;
// 启动静态资源服务器
if (library?.path && config?.staticServerPort) {
void startStaticServer(
join(library.path, "images"),
config.staticServerPort,
);
}

// 启动主题服务器
const themeServerPort =
config?.themeServerPort ??
(await getPort({ port: portNumbers(9301, 9500) }));

if (IS_DEV) {
// TODO: xxx
// dialog.showErrorBox("IS_DEV", IS_DEV + "");
} else {
const child = cp.fork(
join(
process.resourcesPath,
"themes",
config?.theme ?? DEFAULT_THEME,
"server.js",
),
["child"],
{
env: { PORT: themeServerPort.toString(), HOSTNAME: "0.0.0.0" },
signal,
},
);

child.on("error", (e) => {
dialog.showErrorBox("child process fork error", e.message);
controller.abort();
});
}

void caller.config.upsert({
themeServerPort,
});
})
.catch((e) => {
throw e;
const config = await initConfig();
// 启动静态资源服务器
await startStaticServer();

const { themeServerPort } = config;

if (!themeServerPort) return;

if (!IS_DEV) {
const child = cp.fork(
join(
process.resourcesPath,
"themes",
config?.theme ?? DEFAULT_THEME,
"server.js",
),
["child"],
{
env: { PORT: themeServerPort.toString(), HOSTNAME: "0.0.0.0" },
signal,
},
);

child.on("error", (e) => {
dialog.showErrorBox("child process fork error", e.message);
controller.abort();
});
}

// Default open or close DevTools by F12 in development
// and ignore CommandOrControl + R in production.
Expand Down
48 changes: 46 additions & 2 deletions packages/api/src/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
width: z.number(),
height: z.number(),
mtime: z.date(),
thumbnailPath: z.string().optional(),
duration: z.number().optional(),
annotation: z.string().optional(),
url: z.string().optional(),
isDeleted: z.boolean().optional(),
blurDataURL: z.string().optional(),
tags: z
.object({
connect: z.array(z.string()).optional(),
Expand Down Expand Up @@ -76,12 +76,12 @@
ext: input.ext,
width: input.width,
height: input.height,
thumbnailPath: input.thumbnailPath,
duration: input.duration,
annotation: input.annotation,
url: input.url,
mtime: input.mtime,
isDeleted: input.isDeleted,
blurDataURL: input.blurDataURL,
};

const { tags, id, colors, folders } = input;
Expand Down Expand Up @@ -137,6 +137,50 @@
return res;
}),

update: t.procedure
.input(
z
.object({
id: z.number().optional(),
path: z.string().optional(),
name: z.string().optional(),
size: z.number().optional(),
ext: z.string().optional(),
width: z.number().optional(),
height: z.number().optional(),
mtime: z.date().optional(),
duration: z.number().optional(),
annotation: z.string().optional(),
url: z.string().optional(),
isDeleted: z.boolean().optional(),
blurDataURL: z.string().optional(),
})
.partial()
.refine(
(data) => !!data.id || !!data.path,
"id or path either one is required",
),
)
.mutation(async ({ input }) => {
const { id, path, ...data } = input;
if (id) {
return prisma.image.update({
where: { id },
data: {
...data,
path,
},
});
}

if (path) {
return prisma.image.update({
where: { path },
data,
});
}

Check warning on line 181 in packages/api/src/image.ts

View check run for this annotation

Codecov / codecov/patch

packages/api/src/image.ts#L165-L181

Added lines #L165 - L181 were not covered by tests
}),

deleteByUnique: t.procedure
.input(
z
Expand Down
18 changes: 5 additions & 13 deletions packages/api/src/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,16 @@ export const library = t.router({
throw new Error("Cannot add more than one library.");
}

const caller = router.createCaller({});
const config = await caller.config.get();

const port = await startStaticServer(
input,
config?.staticServerPort ?? undefined,
);

if (port) {
await caller.config.upsert({ staticServerPort: port });
}

return await prisma.library.create({
const lib = await prisma.library.create({
data: {
path: input,
type: "eagle",
},
});

await startStaticServer();

return lib;
}),

update: t.procedure
Expand Down
6 changes: 6 additions & 0 deletions packages/api/test/library.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe("library module", () => {
});

describe("add procedure", () => {
beforeEach(async () => {
await caller.config.upsert({
staticServerPort: 9100,
});
});

it("should create a new library when none exist", async () => {
const input = "path/to/xxx.library";
const result = await caller.library.add(input);
Expand Down
40 changes: 20 additions & 20 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,41 @@ model Pending {
}

model Image {
id Int @id @unique @default(autoincrement())
// library.path + path => originalPath
path String @unique
id Int @id @unique @default(autoincrement())
// 完整地址
path String @unique
// 名字
name String
name String
// 文件大小
size Int
size Int
// 创建时间
createdTime DateTime @default(now())
createdTime DateTime @default(now())
// 修改时间
updateTime DateTime @updatedAt
updateTime DateTime @updatedAt
// 文件的 mtime
mtime DateTime
mtime DateTime
// 扩展名
ext String
ext String
// 宽度
width Int
width Int
// 高度
height Int
height Int
// 是否删除
isDeleted Boolean @default(false)
// UserData 缓存目录 + thumbnailPath => thumbnailPath
thumbnailPath String?
isDeleted Boolean @default(false)
// 视频时长
duration Float?
duration Float?
// 描述
annotation String?
annotation String?
// 链接
url String?
url String?
// 颜色
colors Color[]
colors Color[]
// 文件夹
folders Folder[]
folders Folder[]
// 标签
tags Tag[]
tags Tag[]
// blurDataURL Base64
blurDataURL String?
}

model Tag {
Expand Down
5 changes: 0 additions & 5 deletions packages/static-server/dev.ts

This file was deleted.

4 changes: 1 addition & 3 deletions packages/static-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"main": "./index.ts",
"scripts": {
"clean": "git clean -xdf .turbo node_modules",
"dev": "ts-node ./dev.ts",
"format": "prettier --check \"**/*.{mjs,ts,md,json}\"",
"lint": "eslint .",
"typecheck": "tsc --noEmit"
Expand All @@ -21,8 +20,8 @@
]
},
"dependencies": {
"@rao-pics/api": "workspace:^",
"express": "^4.18.2",
"get-port": "^7.0.0",
"plaiceholder": "^3.0.0",
"sharp": "^0.32.5"
},
Expand All @@ -34,7 +33,6 @@
"@types/node": "^18.17.6",
"@types/serve-static": "^1.15.2",
"eslint": "^8.47.0",
"ts-node": "^10.9.1",
"typescript": "^5.1.6"
}
}
Loading