Skip to content

Commit

Permalink
use frontend api
Browse files Browse the repository at this point in the history
  • Loading branch information
zizdlp committed Sep 7, 2024
1 parent 867f97a commit 236877c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ To run a local version of this project, please follow these simple steps.

3. Then open the space in your web browser, using <http://localhost:3000/>

4. 🍻 To use email services and third-party account login, please apply first. For details, please refer to [ZBook User Guide](https://github.com/zizdlp/zbook-user-guide).
4. 🍻 To use email services and third-party account login, please apply first. For details, please refer to [ZBook Documentation](https://github.com/zizdlp/zbook-docs).

### CI and testing

Expand Down Expand Up @@ -89,7 +89,7 @@ ZBook does **not support online editing**. We believe that tools like Git in loc

## Deployment

For privacy and other reasons (for private repositories, you may need to input an access token; although GitHub supports fine-grained access tokens that can grant specific permissions to specific repositories, such as read-only), we encourage you to deploy ZBook yourself. You can use docker-compose or a k8s cluster for deployment. For details, please refer to the [ZBook User Guide](https://github.com/zizdlp/zbook-user-guide).
For privacy and other reasons (for private repositories, you may need to input an access token; although GitHub supports fine-grained access tokens that can grant specific permissions to specific repositories, such as read-only), we encourage you to deploy ZBook yourself. You can use docker-compose or a k8s cluster for deployment. For details, please refer to the [ZBook Documentation](https://github.com/zizdlp/zbook-docs).

## License

Expand Down
4 changes: 2 additions & 2 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

3. 然后在你的网页浏览器中打开 <http://localhost:3000/>

4. 🍻 要使用电子邮件服务和第三方账户登录,请先申请。详情请参阅 [ZBook 用户指南](https://github.com/zizdlp/zbook-user-guide).
4. 🍻 要使用电子邮件服务和第三方账户登录,请先申请。详情请参阅 [ZBook 文档](https://github.com/zizdlp/zbook-docs).

### CI 和测试

Expand Down Expand Up @@ -90,7 +90,7 @@ ZBook 不支持**在线编辑**。我们认为 Git 在本地环境如 VS Code

## 部署

由于隐私和其他原因(对于私人仓库,你可能需要输入访问令牌;虽然 GitHub 支持细粒度访问令牌,可以授予特定仓库的特定权限,例如只读),我们鼓励你自行部署 ZBook。你可以使用 Docker Compose 或 k8s 集群进行部署。详情请参阅 [ZBook 用户指南](https://github.com/zizdlp/zbook-user-guide)。
由于隐私和其他原因(对于私人仓库,你可能需要输入访问令牌;虽然 GitHub 支持细粒度访问令牌,可以授予特定仓库的特定权限,例如只读),我们鼓励你自行部署 ZBook。你可以使用 Docker Compose 或 k8s 集群进行部署。详情请参阅 [ZBook 文档](https://github.com/zizdlp/zbook-docs)。

## 许可

Expand Down
2 changes: 1 addition & 1 deletion zbook_backend/statik/statik.go

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions zbook_frontend/src/app/api/sync/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { fetchServerWithoutAuthWrapper } from "@/fetchs/server_without_auth";
import { FetchServerWithoutAuthWrapperEndPoint } from "@/fetchs/server_without_auth_util";

export const dynamic = "force-dynamic"; // defaults to auto
export async function GET(request: Request) {
try {
const urlParams = new URLSearchParams(request.url.split("?")[1]);
const username = urlParams.get("username");
const repo_name = urlParams.get("repo_name");
const sync_token = urlParams.get("sync_token");

const data = await fetchServerWithoutAuthWrapper({
endpoint: FetchServerWithoutAuthWrapperEndPoint.AUTO_SYNC_REPO,
values: {
username: username ?? "",
repo_name: repo_name ?? "",
sync_token: sync_token ?? "",
},
xforward: "",
agent: "",
});

return Response.json(data);
} catch (error) {
console.error(error);
return Response.error();
}
}
12 changes: 12 additions & 0 deletions zbook_frontend/src/fetchs/server_without_auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
createUserRequest,
refreshTokenRequest,
LogVisitorRequest,
AutoSyncRepoRequest,
} from "./server_without_auth_request";
import { FetchServerWithoutAuthWrapperEndPoint } from "./server_without_auth_util";
import { fetchServer } from "./server_with_auth";
Expand Down Expand Up @@ -70,6 +71,17 @@ export async function fetchServerWithoutAuthWrapper({
xforward: string;
agent: string;
}): Promise<any>;
export async function fetchServerWithoutAuthWrapper({
endpoint,
values,
xforward,
agent,
}: {
endpoint: FetchServerWithoutAuthWrapperEndPoint.AUTO_SYNC_REPO;
values: AutoSyncRepoRequest;
xforward: string;
agent: string;
}): Promise<any>;
export async function fetchServerWithoutAuthWrapper({
endpoint,
values,
Expand Down
6 changes: 6 additions & 0 deletions zbook_frontend/src/fetchs/server_without_auth_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ interface LoginUserRequest {
email: string;
password: string;
}
interface AutoSyncRepoRequest {
username: string;
repo_name: string;
sync_token: string;
}
interface LoginByOAuthRequest {
oauth_type: string;
app_id: string;
Expand All @@ -42,4 +47,5 @@ export type {
LoginUserRequest,
LoginByOAuthRequest,
LogVisitorRequest,
AutoSyncRepoRequest,
};
1 change: 1 addition & 0 deletions zbook_frontend/src/fetchs/server_without_auth_util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum FetchServerWithoutAuthWrapperEndPoint {
LOGIN_USER = "login_user",
LOGIN_BY_OAUTH = "login_by_oauth",
LOG_VISITOR = "log_visitor",
AUTO_SYNC_REPO = "auto_sync_repo",
}

0 comments on commit 236877c

Please sign in to comment.