Skip to content

Commit e3f4a37

Browse files
committed
添加调试信息
1 parent 69225d8 commit e3f4a37

5 files changed

Lines changed: 39 additions & 16 deletions

File tree

pages/dashboard/article.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import GridStatusBar from '~/components/grid/StatusBar.vue';
1717
import GridCoverTooltip from '~/components/grid/CoverTooltip.vue';
1818
import { AG_GRID_LOCALE_CN } from '@ag-grid-community/locale';
1919
import { type Info } from '~/store/v2/info';
20-
import { getArticleCache, articleDeleted } from '~/store/v2/article';
20+
import { getArticleCache, articleDeleted, getArticleByLink } from '~/store/v2/article';
2121
import type { AppMsgEx } from '~/types/types';
2222
import { formatElapsedTime, formatTimeStamp, sleep, ITEM_SHOW_TYPE, durationToSeconds } from '~/utils';
2323
import { Downloader } from '~/utils/download/Downloader';
@@ -27,9 +27,9 @@ import { getCommentCache } from '~/store/v2/comment';
2727
import type { ArticleMetadata, DownloaderStatus, ExporterStatus } from '~/utils/download/types';
2828
import { getMetadataCache, type Metadata } from '~/store/v2/metadata';
2929
import type { PreviewArticle } from '#components';
30-
import TurndownService from 'turndown';
3130
import type { Preferences } from '~/types/preferences';
3231
import AccountSelectorForArticle from '~/components/selector/AccountSelectorForArticle.vue';
32+
import { isDev } from '~/config';
3333
3434
let globalRowData: Article[] = [];
3535
@@ -386,7 +386,6 @@ function onFilterChanged(event: FilterChangedEvent) {
386386
event.api.deselectAll();
387387
}
388388
389-
const isDev = !import.meta.env.PROD;
390389
const preferences = usePreferences();
391390
const hideDeleted = computed(() => (preferences.value as unknown as Preferences).hideDeleted);
392391
@@ -962,9 +961,8 @@ async function export2word() {
962961
}
963962
964963
async function debug() {
965-
const turndownService = new TurndownService();
966-
const markdown = turndownService.turndown('<h1>Hello world!</h1>');
967-
console.debug(markdown);
964+
const article = await getArticleByLink('https://mp.weixin.qq.com/s/8sCrH6AZyyff5dVXQAzVFQ');
965+
console.log(article);
968966
}
969967
</script>
970968

server/api/_debug.get.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { cookieStore } from '~/server/utils/CookieStore';
2+
3+
interface DebugQuery {
4+
key: string;
5+
}
6+
7+
export default defineEventHandler(async event => {
8+
const { key } = getQuery<DebugQuery>(event);
9+
if (key && key === process.env.DEBUG_KEY) {
10+
return cookieStore.toJSON();
11+
} else {
12+
return 'not set debug key';
13+
}
14+
});

server/kv/cookie.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ export interface CookieKVValue {
99

1010
export async function setMpCookie(key: CookieKVKey, data: CookieKVValue): Promise<boolean> {
1111
const kv = useStorage('kv');
12-
await kv.set<CookieKVValue>(`cookie:${key}`, data, {
13-
// https://developers.cloudflare.com/kv/api/write-key-value-pairs/#expiring-keys
14-
expirationTtl: 60 * 60 * 24 * 4, // 4 days
15-
});
16-
return true;
12+
try {
13+
await kv.set<CookieKVValue>(`cookie:${key}`, data, {
14+
// https://developers.cloudflare.com/kv/api/write-key-value-pairs/#expiring-keys
15+
expirationTtl: 60 * 60 * 24 * 4, // 4 days
16+
});
17+
return true;
18+
} catch (err) {
19+
console.error('kv.set call failed:', err);
20+
return false;
21+
}
1722
}
1823

1924
export async function getMpCookie(key: CookieKVKey): Promise<CookieKVValue | null> {

server/utils/CookieStore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ class CookieStore {
148148
* @param token
149149
* @param cookie 原始的 set-cookie 字符串数组
150150
*/
151-
async setCookie(authKey: string, token: string, cookie: string[]) {
151+
async setCookie(authKey: string, token: string, cookie: string[]): Promise<boolean> {
152152
const accountCookie = new AccountCookie(token, cookie);
153153
this.store.set(authKey, accountCookie);
154-
await setMpCookie(authKey, accountCookie.toJSON());
154+
return await setMpCookie(authKey, accountCookie.toJSON());
155155
}
156156

157157
/**

server/utils/proxy-request.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,22 @@ export async function proxyMpRequest(options: RequestOptions) {
7575

7676
const { redirect_url } = await mpResponse.clone().json();
7777
const token = new URL(`http://localhost${redirect_url}`).searchParams.get('token')!;
78-
await cookieStore.setCookie(authKey, token, mpResponse.headers.getSetCookie());
78+
console.log('token', token);
79+
const success = await cookieStore.setCookie(authKey, token, mpResponse.headers.getSetCookie());
80+
if (success) {
81+
console.log('cookie 写入成功');
82+
} else {
83+
console.log('cookie 写入失败');
84+
}
7985

8086
setCookies = [
8187
`auth-key=${authKey}; Path=/; Expires=${dayjs().add(4, 'days').toString()}; Secure; HttpOnly`,
8288

8389
// 登录成功后,删除浏览器的 uuid cookie
8490
`uuid=EXPIRED; Path=/; Expires=${dayjs().subtract(1, 'days').toString()}; Secure; HttpOnly`,
8591
];
86-
} catch (err) {
87-
console.error(err);
92+
} catch (error) {
93+
console.error('action(login) failed:', error);
8894
}
8995
}
9096

0 commit comments

Comments
 (0)