diff --git a/src/api/auth.js b/src/api/auth.js index da40e6a..bffad39 100644 --- a/src/api/auth.js +++ b/src/api/auth.js @@ -27,7 +27,7 @@ export function loginWithEmail(params) { }); } -export function loginRefresh() { +export function refreshCookie() { return request({ url: "/login/refresh", method: "post", diff --git a/src/main.js b/src/main.js index e296e80..b30c465 100644 --- a/src/main.js +++ b/src/main.js @@ -8,6 +8,7 @@ import "@/assets/icons"; import "@/utils/filters"; import { initMediaSession } from "@/utils/mediaSession"; import "./registerServiceWorker"; +import { dailyTask } from "@/utils/common"; import * as Sentry from "@sentry/browser"; import { Vue as VueIntegration } from "@sentry/integrations"; @@ -41,6 +42,8 @@ if (process.env.VUE_APP_ENABLE_SENTRY === "true") { }); } +dailyTask(); + new Vue({ i18n, store, diff --git a/src/store/initState.js b/src/store/initState.js index 70c45a0..1ed6568 100644 --- a/src/store/initState.js +++ b/src/store/initState.js @@ -86,6 +86,9 @@ const initState = { }, lang: null, musicQuality: 320000, + showGithubIcon: true, + showPlaylistsByAppleMusic: true, + lastRefreshCookieDate: 0, }, }; diff --git a/src/utils/common.js b/src/utils/common.js index f94b8bc..cf693f0 100644 --- a/src/utils/common.js +++ b/src/utils/common.js @@ -1,4 +1,6 @@ import { isAccountLoggedIn } from "./auth"; +import { refreshCookie } from "@/api/auth"; +import dayjs from "dayjs"; import store from "@/store"; export function isTrackPlayable(track) { @@ -61,7 +63,7 @@ export function shuffleAList(list) { export function throttle(fn, time) { let isRun = false; - return function () { + return function() { if (isRun) return; isRun = true; fn.apply(this, arguments); @@ -75,3 +77,17 @@ export function updateHttps(url) { if (!url) return ""; return url.replace(/^http:/, "https:"); } + +export function dailyTask() { + if ( + store.state.settings.lastRefreshCookieDate === undefined || + store.state.settings.lastRefreshCookieDate !== dayjs().date() + ) { + console.log("execute dailyTask"); + store.commit("updateSettings", { + key: "lastRefreshCookieDate", + value: dayjs().date(), + }); + refreshCookie(); + } +} diff --git a/src/views/library.vue b/src/views/library.vue index efa986e..c2115d8 100644 --- a/src/views/library.vue +++ b/src/views/library.vue @@ -58,7 +58,7 @@ import { mapState } from "vuex"; import { getTrackDetail, getLyric } from "@/api/track"; import { userDetail, userPlaylist } from "@/api/user"; -import { randomNum } from "@/utils/common"; +import { randomNum, dailyTask } from "@/utils/common"; import { getPlaylistDetail } from "@/api/playlist"; import { playPlaylistByID } from "@/utils/play"; import NProgress from "nprogress"; @@ -98,6 +98,7 @@ export default { }, activated() { this.loadData(); + dailyTask(); }, computed: { ...mapState(["settings"]),