Skip to content

Commit

Permalink
Fix fetch server config
Browse files Browse the repository at this point in the history
  • Loading branch information
sunls24 committed Apr 28, 2024
1 parent 6e94651 commit 2f39e25
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
7 changes: 5 additions & 2 deletions app/api/config/route.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { NextRequest, NextResponse } from "next/server";
import { DOMAIN_LIST_SERVER } from "@/lib/constant";
import { ConfigServer } from "@/lib/store/config-server";
import { getDomainList } from "@/lib/utils";
import { unstable_noStore as noStore } from "next/cache";

export async function GET(req: NextRequest) {
const config: ConfigServer = { domain: DOMAIN_LIST_SERVER };
noStore();
const config: ConfigServer = { domain: getDomainList() };
console.log("config:", config);
return NextResponse.json(config);
}
4 changes: 2 additions & 2 deletions app/api/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ImapFlow, SearchObject } from "imapflow";
import { Envelope } from "@/lib/types";
import { DOMAIN_LIST_SERVER } from "@/lib/constant";
import { getDomainList } from "@/lib/utils";

let client: ImapFlow;
let connecting: Promise<void> | undefined;
Expand Down Expand Up @@ -81,7 +81,7 @@ export async function fetchLast10Day() {
const now = new Date().getTime();
return await run(async () => {
const data = { day10: 0, hour24: 0 };
for (let domain of DOMAIN_LIST_SERVER) {
for (let domain of getDomainList()) {
for await (let msg of client.fetch(
{ since: new Date(now - DAY10), to: `*${domain}` },
{ internalDate: true },
Expand Down
6 changes: 1 addition & 5 deletions lib/constant.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const DOMAIN_LIST_ENV = process.env.DOMAIN_LIST ?? "@not.set.yet";

export const DOMAIN_LIST_SERVER = DOMAIN_LIST_ENV.split("|");

export const REFRESH_SECONDS =
process.env.NODE_ENV === "development" ? 1000 : 10;

export const VERSION = "1.0.2";
export const VERSION = "1.0.3";
4 changes: 4 additions & 0 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ export function delay(milliseconds: number) {
setTimeout(resolve, milliseconds);
});
}

export function getDomainList() {
return (process.env.DOMAIN_LIST ?? "@not.set.yet").split("|");
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "temporary-mail",
"version": "1.0.2",
"version": "0.0.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit 2f39e25

Please sign in to comment.