Skip to content

Commit

Permalink
Feat: import audio/video in batch (#715)
Browse files Browse the repository at this point in the history
* refactor audios table

* import audio/video in batch

* add search & filter for audios/videos

* fix locale
  • Loading branch information
an-lee authored Jun 25, 2024
1 parent 0dc17de commit 0e4c1f4
Show file tree
Hide file tree
Showing 9 changed files with 411 additions and 244 deletions.
12 changes: 11 additions & 1 deletion enjoy/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@
"text": "text",
"addResource": "add resource",
"addResourceFromUrlOrLocal": "add resource from url or local",
"resourceAdded": "Resource added",
"resourcesAdded": "{{fulfilled}} resources added, {{rejected}} failed to add.",
"editResource": "edit resource",
"deleteResource": "delete resource",
"deleteResourceConfirmation": "Are you sure to delete {{name}}?",
Expand Down Expand Up @@ -611,6 +613,14 @@
"sortBy": "Sort by",
"createdAtDesc": "Created at desc",
"createdAtAsc": "Created at asc",
"updatedAtDesc": "Updated at desc",
"updatedAtAsc": "Updated at asc",
"scoreDesc": "Score desc",
"scoreAsc": "Score asc"
"scoreAsc": "Score asc",
"recordingsDurationDesc": "Recordings duration",
"recordingsCountDesc": "Recordings duration",
"all": "All",
"allLanguages": "All languages",
"search": "Search",
"noData": "No data"
}
12 changes: 11 additions & 1 deletion enjoy/src/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@
"text": "文本",
"addResource": "添加资源",
"addResourceFromUrlOrLocal": "添加资源, 可以是 URL 或本地文件",
"resourceAdded": "资源添加成功",
"resourcesAdded": "成功添加 {{fulfilled}} 个资源, {{rejected}} 个资源添加失败",
"editResource": "编辑资源",
"deleteResource": "删除资源",
"deleteResourceConfirmation": "您确定要删除资源 {{name}} 吗?",
Expand Down Expand Up @@ -611,6 +613,14 @@
"sortBy": "排序",
"createdAtDesc": "创建时间降序",
"createdAtAsc": "创建时间升序",
"updatedAtDesc": "更新时间降序",
"updatedAtAsc": "更新时间升序",
"scoreDesc": "得分从高到低",
"scoreAsc": "得分从低到高"
"scoreAsc": "得分从低到高",
"recordingsDurationDesc": "录音时长",
"recordingsCountDesc": "录音次数",
"all": "全部",
"allLanguages": "全部语言",
"search": "搜索",
"noData": "没有数据"
}
14 changes: 12 additions & 2 deletions enjoy/src/main/db/handlers/audios-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ipcMain, IpcMainEvent } from "electron";
import { Audio, Transcription } from "@main/db/models";
import { FindOptions, WhereOptions, Attributes } from "sequelize";
import { FindOptions, WhereOptions, Attributes, Op } from "sequelize";
import downloader from "@main/downloader";
import log from "@main/logger";
import { t } from "i18next";
Expand All @@ -12,8 +12,17 @@ const logger = log.scope("db/handlers/audios-handler");
class AudiosHandler {
private async findAll(
_event: IpcMainEvent,
options: FindOptions<Attributes<Audio>>
options: FindOptions<Attributes<Audio>> & { query?: string }
) {
const { query, where = {} } = options || {};
delete options.query;
delete options.where;

if (query) {
(where as any).name = {
[Op.like]: `%${query}%`,
};
}
const audios = await Audio.findAll({
order: [["updatedAt", "DESC"]],
include: [
Expand All @@ -24,6 +33,7 @@ class AudiosHandler {
required: false,
},
],
where,
...options,
});

Expand Down
14 changes: 12 additions & 2 deletions enjoy/src/main/db/handlers/videos-handler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ipcMain, IpcMainEvent } from "electron";
import { Video, Transcription } from "@main/db/models";
import { FindOptions, WhereOptions, Attributes } from "sequelize";
import { FindOptions, WhereOptions, Attributes, Op } from "sequelize";
import downloader from "@main/downloader";
import log from "@main/logger";
import { t } from "i18next";
Expand All @@ -12,8 +12,17 @@ const logger = log.scope("db/handlers/videos-handler");
class VideosHandler {
private async findAll(
_event: IpcMainEvent,
options: FindOptions<Attributes<Video>>
options: FindOptions<Attributes<Video>> & { query?: string }
) {
const { query, where = {} } = options || {};
delete options.query;
delete options.where;

if (query) {
(where as any).name = {
[Op.like]: `%${query}%`,
};
}
const videos = await Video.findAll({
order: [["updatedAt", "DESC"]],
include: [
Expand All @@ -24,6 +33,7 @@ class VideosHandler {
required: false,
},
],
where,
...options,
});
if (!videos) {
Expand Down
Loading

0 comments on commit 0e4c1f4

Please sign in to comment.