Skip to content

Commit

Permalink
fix(monkey): 可以选择不导出关注列表
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilfish committed Apr 21, 2024
1 parent 8a7f683 commit 05b9345
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 25 deletions.
4 changes: 0 additions & 4 deletions apps/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ export type Config = Omit<FetchOptions, 'name'> & {
* @default ~/weibo-archiver/
*/
savePath: string
/**
* 只爬取微博
*/
weiboOnly: boolean
}

export async function getConfig(
Expand Down
21 changes: 16 additions & 5 deletions apps/monkey/src/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,22 @@ const dateRange = computed({
重置为所有微博
</button>
</div>
<n-checkbox
v-model:checked="config.followingsOnly"
label="只导出关注列表"
size="small"
/>

<div>
<n-checkbox
v-if="!config.weiboOnly"
v-model:checked="config.followingsOnly"
label="只导出关注列表"
size="small"
/>
<n-checkbox
v-if="!config.followingsOnly"
v-model:checked="config.weiboOnly"
label="只导出微博"
size="small"
/>
</div>

<div
v-show="config.hasComment"
class="flex items-center gap-4"
Expand Down
15 changes: 9 additions & 6 deletions apps/monkey/src/Ctrl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ const { pause, start } = fetchPosts({
}),
setTotal: total => postStore.total = total,
onFinish: async () => {
message.success('获取完毕~,正在获取关注列表')
isFetchingFollowings.value = true
await fetchFollowings(
config.value.uid,
async data => postStore.addFollowings(data),
)
if (!config.value.weiboOnly) {
message.success('获取完毕~,正在获取关注列表')
isFetchingFollowings.value = true
await fetchFollowings(
config.value.uid,
async data => postStore.addFollowings(data),
)
}
await postStore.exportDatas()
isStart.value = false
Expand Down
1 change: 1 addition & 0 deletions apps/monkey/src/stores/configStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const useConfigStore = defineStore('config', () => {
hasFavorite: true,
commentCount: 6,
followingsOnly: false,
weiboOnly: false,
startAt: now,
endAt: now,
}
Expand Down
6 changes: 4 additions & 2 deletions apps/monkey/src/stores/postStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ export const usePostStore = defineStore('post', () => {
const posts = await getAll()
console.log('导出的数量:', posts.length)

const followings = await idb.value.getFollowings()
const followings = config.value.weiboOnly
? []
: await idb.value.getFollowings()

const res = await exportData(posts, userInfo.value, followings)
if (!res)
return
const scripts = 'https://github.com/Chilfish/Weibo-archiver/raw/monkey/scripts.zip'
saveAs(scripts, 'scripts.zip')
saveAs(scripts, 'weibo-archiver-scripts.zip')
}

return {
Expand Down
22 changes: 14 additions & 8 deletions packages/shared/src/services/userService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,20 @@ export async function getMyFollowings(
}

export async function isMe(uid: string) {
const [withoutUid, withUid] = await Promise.all([
weiFetch('/profile/detail'),
weiFetch('/profile/detail', {
params: { uid },
}),
])

return withUid.data.created_at === withoutUid.data.created_at
try {
const [withoutUid, withUid] = await Promise.all([
weiFetch('/profile/detail'),
weiFetch('/profile/detail', {
params: { uid },
}),
])

return withUid.data.created_at === withoutUid.data.created_at
}
catch (e) {
console.error('isMe error', e)
return false
}
}

export async function fetchFollowings(
Expand Down
5 changes: 5 additions & 0 deletions packages/shared/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ export interface FetchOptions {
*/
cookie?: string

/**
* 只爬取微博
*/
weiboOnly: boolean

/**
* 保存帖子
*/
Expand Down

0 comments on commit 05b9345

Please sign in to comment.