Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/hooks/graph/useSync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const useSync = () => {
return typeof playlist === 'object' && playlist !== null && 'title' in playlist && 'fileList' in playlist
}

function isTrack(item: unknown): item is Track {
return typeof item === 'object' && item !== null && 'id' in item && typeof item.id === 'string' && 'name' in item && typeof item.name === 'string'
}

// 自动从 OneDrive 获取应用数据
const appDatafetcher = async () => {
if (!account) return {
Expand Down Expand Up @@ -61,7 +65,7 @@ const useSync = () => {
size: item.fileSize,
})
: item
)
).filter(isTrack)

const playlists: Playlist[] = remotePlaylists.map((playlist) =>
isOldPlaylist(playlist)
Expand All @@ -75,7 +79,10 @@ const useSync = () => {
size: item.fileSize,
})),
})
: playlist
: {
...playlist,
files: playlist.files.filter(isTrack),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

如果对播放列表过滤,由于旧版本播放列表文件并没有id信息可能导致清空播放列表

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我个人能想到的解决办法:

  1. 将id设置为空字符串,就像history.json那样处理
  2. 将Track设置为“id或path至少有一个存在”,然后需要id的地方做判断,实时获取id
  3. 迁移的时候从delta data或者OneDrive api获取id

}
)

return {
Expand Down Expand Up @@ -125,4 +132,4 @@ const useSync = () => {

}

export default useSync
export default useSync
11 changes: 10 additions & 1 deletion src/store/useHistoryStore.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { HistoryActions, HistoryState } from '../types/history'
import { Track } from '../types/file'
import { create } from 'zustand'
import createSelectors from './createSelectors'

const hasSameNonEmptyPath = (a: Track, b: Track) => (
Array.isArray(a.path)
&& a.path.length > 0
&& Array.isArray(b.path)
&& b.path.length > 0
&& a.path.join('/') === b.path.join('/')
)

const useHistoryStoreBase = create<HistoryState & HistoryActions>(
(set) => ({
historys: null,
Expand All @@ -13,7 +22,7 @@ const useHistoryStoreBase = create<HistoryState & HistoryActions>(
historys:
[
file,
...state.historys.filter((item) => item.path.join('/') !== file.path.join('/'))
...state.historys.filter((item) => !hasSameNonEmptyPath(item, file)),
].slice(0, 200)
}
: { historys: [file] }
Expand Down
Loading