Skip to content

Commit 6ccf1d0

Browse files
committed
fix: replace pixivClient singleton with store object
1 parent 306252e commit 6ccf1d0

20 files changed

Lines changed: 51 additions & 42 deletions

File tree

app/api/pixiv-client.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ export interface FollowingResult {
5757

5858
// ── PixivWebClient ───────────────────────────────────────────────────
5959

60-
function resolveBaseUrl(
61-
fallback: string,
62-
override?: string
63-
): string {
60+
function resolveBaseUrl(fallback: string, override?: string): string {
6461
if (override) return override.endsWith('/') ? override : override + '/'
6562
return fallback
6663
}
@@ -430,8 +427,3 @@ export class PixivWebClient {
430427
return this.transform(data)
431428
}
432429
}
433-
434-
/**
435-
* Singleton instance for use across the application.
436-
*/
437-
export const pixivClient = new PixivWebClient()

app/components/Artwork/ArtworkCard.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@
1111
.artwork-card(v-else-if='item')
1212
.artwork-image
1313
.side-tags
14-
.restrict.x-restrict(aria-label='R-18' role='img' title='R-18' v-if='item.xRestrict')
14+
.restrict.x-restrict(
15+
aria-label='R-18'
16+
role='img'
17+
title='R-18'
18+
v-if='item.xRestrict'
19+
)
1520
IFasEye(aria-hidden='true')
1621
.restrict.ai-restrict(
17-
:aria-label='`AI生成`'
22+
:aria-label='`AI生成`',
1823
:title='`AI生成(${item.aiType})`'
1924
role='img'
2025
v-if='item.aiType === 2'
@@ -27,8 +32,8 @@
2732
IFasImages(data-icon)
2833
| {{ item.pageCount }}
2934
button.bookmark(
30-
:aria-label='item.bookmarkData ? "取消收藏" : "添加收藏"'
31-
:class='{ bookmarked: item.bookmarkData, disabled: loadingBookmark }'
35+
:aria-label='item.bookmarkData ? "取消收藏" : "添加收藏"',
36+
:class='{ bookmarked: item.bookmarkData, disabled: loadingBookmark }',
3237
:title='item.bookmarkData ? "取消收藏" : "添加收藏"'
3338
@click.stop.prevent='handleBookmark'
3439
)
@@ -53,22 +58,22 @@
5358

5459
<script lang="ts" setup>
5560
import DeferLoad from '../DeferLoad.vue'
56-
import { pixivClient } from '~/api/pixiv-client'
5761
import { NSkeleton } from 'naive-ui'
5862
import { IllustType } from '~/utils/constants'
5963
import IFasEye from '~icons/fa-solid/eye'
6064
import IFasHeart from '~icons/fa-solid/heart'
6165
import IFasImages from '~icons/fa-solid/images'
6266
import IFasRobot from '~icons/fa-solid/robot'
6367
import IPlayCircle from '~icons/fa-solid/play-circle'
64-
6568
import type { ArtworkInfo } from '~/types'
6669
6770
const props = defineProps<{
6871
item?: ArtworkInfo
6972
loading?: boolean
7073
}>()
7174
75+
const pixivClient = usePixivClientStore().client
76+
7277
const loadingBookmark = ref(false)
7378
async function handleBookmark() {
7479
if (loadingBookmark.value) return

app/components/AuthorCard.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
<script lang="ts" setup>
3838
import ArtworkList from './Artwork/ArtworkList.vue'
3939
import type { User } from '~/types'
40-
import { pixivClient } from '~/api/pixiv-client'
4140
import { NButton, NEllipsis, NSkeleton } from 'naive-ui'
4241
import IFasCheck from '~icons/fa-solid/check'
4342
import IFasPlus from '~icons/fa-solid/plus'

app/components/Comment/CommentArea.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
<script lang="ts" setup>
2626
import Comment from './Comment.vue'
27-
import { pixivClient } from '~/api/pixiv-client'
2827
import type { Comments } from '~/types'
2928
import { NButton } from 'naive-ui'
3029
import IFasPlus from '~icons/fa-solid/plus'

app/components/FollowUserCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737
<script lang="ts" setup>
3838
import ArtworkList from './Artwork/ArtworkList.vue'
3939
import type { User, UserListItem } from '~/types'
40-
import { pixivClient } from '~/api/pixiv-client'
4140
import { NButton, NEllipsis, NSkeleton } from 'naive-ui'
4241
import IFasCheck from '~icons/fa-solid/check'
4342
import IFasPlus from '~icons/fa-solid/plus'
4443
import { useUserStore } from '~/stores/session'
4544
4645
const userStore = useUserStore()
46+
const pixivClient = usePixivClientStore().client
4747
4848
const props = defineProps<{
4949
user?: UserListItem

app/composables/userData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { PixivUser } from '~/types'
2-
import { pixivClient } from '~/api/pixiv-client'
32
import Cookies from 'js-cookie'
43

54
export function existsSessionId(): boolean {
@@ -13,6 +12,7 @@ export function existsSessionId(): boolean {
1312
}
1413

1514
export async function initUser(): Promise<PixivUser> {
15+
const pixivClient = usePixivClientStore().client
1616
try {
1717
const data = await pixivClient._getSessionUser()
1818
if (data.token) {

app/pages/artworks/[id].vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ import IFasThumbsUp from '~icons/fa-solid/thumbs-up'
150150
151151
// Types
152152
import type { Artwork, ArtworkGallery, User } from '~/types'
153-
154153
import { useUserStore } from '~/stores/session'
155154
import { useArtworkStore } from '~/stores/artwork'
156155
import { useUserProfileStore } from '~/stores/user-profile'

app/pages/index.vue

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@
3030
.bg-info-modal
3131
.align-center
3232
RouterLink.thumb(:to='"/artworks/" + randomBg?.id')
33-
img(:src='randomBgRegularUrl' lazyload :style="{width: '100%', height: 'auto'}")
33+
img(
34+
:src='randomBgRegularUrl',
35+
:style='{ width: "100%", height: "auto" }'
36+
lazyload
37+
)
3438
.desc
3539
.author
3640
RouterLink(:to='"/users/" + randomBg?.userId') @{{ randomBg?.userName }}
@@ -56,28 +60,30 @@
5660
)
5761
template(#default) {{ homeStore.loadingDiscovery ? '加载中' : '换一批' }}
5862
template(#icon): NIcon: IFasRandom
59-
ArtworkList(:list='homeStore.discoveryList', :loading='homeStore.loadingDiscovery')
63+
ArtworkList(
64+
:list='homeStore.discoveryList',
65+
:loading='homeStore.loadingDiscovery'
66+
)
6067
</template>
6168

6269
<script lang="ts" setup>
63-
definePageMeta({ name: 'home' })
64-
65-
// Mark body with route class for navbar transparency
66-
useHead({
67-
bodyAttrs: { 'data-route': 'home' },
68-
})
69-
7070
import ArtworkList from '~/components/Artwork/ArtworkList.vue'
7171
import SearchBox from '~/components/SearchBox.vue'
7272
import { NH2, NButton, NIcon, NModal } from 'naive-ui'
7373
import IFasInfoCircle from '~icons/fa-solid/info-circle'
7474
import IFasRandom from '~icons/fa-solid/random'
75-
7675
import { useHomeStore } from '~/stores/home'
7776
import { toRegularUrl } from '~/utils/pximg'
7877
import LogoH from '~/assets/LogoH.png'
7978
import { setTitle } from '~/utils/setTitle'
8079
80+
definePageMeta({ name: 'home' })
81+
82+
// Mark body with route class for navbar transparency
83+
useHead({
84+
bodyAttrs: { 'data-route': 'home' },
85+
})
86+
8187
const isShowBgInfo = ref(false)
8288
const homeStore = useHomeStore()
8389
const randomBg = computed(() => homeStore.randomBg)

app/pages/ranking.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ definePageMeta({ name: 'ranking' })
2525
import ArtworkLargeList from '~/components/Artwork/ArtworkLargeList.vue'
2626
import ErrorPage from '~/components/ErrorPage.vue'
2727
import Placeholder from '~/components/Placeholder.vue'
28-
2928
import { useRankingStore } from '~/stores/ranking'
3029
import { effect } from 'vue'
3130
import { setTitle } from '~/utils/setTitle'

app/pages/search/[keyword]/[p].vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import ArtworkList from '~/components/Artwork/ArtworkList.vue'
3232
import ErrorPage from '~/components/ErrorPage.vue'
3333
import SearchBox from '~/components/SearchBox.vue'
3434
import { NButton, NSpin } from 'naive-ui'
35-
3635
import { useSearchStore } from '~/stores/search'
3736
import { effect } from 'vue'
3837
import { setTitle } from '~/utils/setTitle'

0 commit comments

Comments
 (0)