Skip to content

Commit

Permalink
fix crash data if quote exec
Browse files Browse the repository at this point in the history
  • Loading branch information
tachibana-shin committed May 30, 2023
1 parent 49c17a1 commit d3b60ac
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 33 deletions.
40 changes: 22 additions & 18 deletions src/components/BrtPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,6 @@ import { scrollXIntoView } from "src/helpers/scrollIntoView"
import { fetchJava } from "src/logic/fetchJava"
import { patcher } from "src/logic/hls-patcher"
import { parseTime } from "src/logic/parseTime"
import { resolveAfter } from "src/logic/resolveAfter"
import { ResponseDataSeasonSuccess } from "src/pages/phim/_season.interface"
import type {
ProgressWatchStore,
Expand Down Expand Up @@ -1096,14 +1095,11 @@ async function createSeason(
)
return false
console.log("set new season poster %s", poster)
await Promise.race([
historyStore.createSeason(currentSeason, {
poster,
seasonName,
name,
}),
resolveAfter(1_200),
])
await historyStore.createSeason(currentSeason, {
poster,
seasonName,
name,
})
seasonMetaCreated.add(currentSeason)
return true
}
Expand Down Expand Up @@ -1136,9 +1132,10 @@ function throttle<T extends (...args: any[]) => void>(
if (wait === false) {
wait = true
timeout = setTimeout(
() => {
async () => {
firstSaveStore.add(uidChap.value)
fn(...args)
// eslint-disable-next-line no-void
await fn(...args).catch(() => void 0)
wait = false
},
firstSaveStore.has(uidChap.value)
Expand Down Expand Up @@ -1214,16 +1211,23 @@ const saveCurTimeToPer = throttle(
dur,
id: currentChap,
})
await Promise.race([
historyStore
.setProgressChap(currentSeason, currentChap, {
historyStore
.setProgressChap(
currentSeason,
currentChap,
{
cur,
dur,
name: nameCurrentChap,
})
.catch((err) => console.warn("save viewing progress failed: ", err)),
resolveAfter(1_200),
])
},
{
poster,
seasonName: nameCurrentChap,
name,
}
)
.catch((err) => console.warn("save viewing progress failed: ", err))
console.log("save viewing progress")
Expand Down
3 changes: 0 additions & 3 deletions src/logic/resolveAfter.ts

This file was deleted.

36 changes: 24 additions & 12 deletions src/stores/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export const useHistoryStore = defineStore("history", () => {
})
)

function loadMoreAfter(
async function loadMoreAfter(
lastDoc?: QueryDocumentSnapshot<Required<HistoryItem>>
) {
if (!authStore.uid)
Expand All @@ -112,7 +112,13 @@ export const useHistoryStore = defineStore("history", () => {
])
)

return getDocs(
const result: (Omit<Required<HistoryItem>, "timestamp"> & {
id: string
timestamp: dayjs.Dayjs
$doc: QueryDocumentSnapshot<Required<HistoryItem>>
})[] = []

const { docs } = await getDocs(
query(
collection(
db,
Expand All @@ -125,24 +131,27 @@ export const useHistoryStore = defineStore("history", () => {
...(lastDoc ? [startAfter(lastDoc)] : []),
limit(30)
)
).then(({ docs }) =>
docs.map((doc) => {
const data = doc.data()
return {
)
docs.forEach((doc) => {
const data = doc.data()

if (data.name)
result.push({
id: doc.id,
...data,
poster: addHostUrlImage(data.poster),
timestamp: dayjs(data.timestamp?.toDate()),
$doc: doc,
}
})
)
})
})

return result
}

async function createSeason(
seasonId: string,
info: Omit<HistoryItem, "timestamp" | "season">
) {
): Promise<void> {
if (!authStore.uid)
// eslint-disable-next-line functional/no-throw-statement
throw new Error(
Expand Down Expand Up @@ -211,7 +220,8 @@ export const useHistoryStore = defineStore("history", () => {
function setProgressChap(
season: string,
chap: string,
info: HistoryItem_ChapItem
info: HistoryItem_ChapItem,
infoSeason: Omit<HistoryItem, "timestamp" | "season">
) {
if (!authStore.uid)
// eslint-disable-next-line functional/no-throw-statement
Expand Down Expand Up @@ -266,11 +276,13 @@ export const useHistoryStore = defineStore("history", () => {

// const batch = writeBatch(db)
await Promise.all([
setDoc(
setDoc<HistoryItem>(
seasonRef,
{
timestamp: serverTimestamp(),
season,
...infoSeason,
poster: removeHostUrlImage(infoSeason.poster),
last: {
chap,
...info,
Expand Down

0 comments on commit d3b60ac

Please sign in to comment.