mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-01-19 20:32:45 +08:00
feat: refresh cookie every day to keep user logged in
This commit is contained in:
parent
780b429fa9
commit
7d456f7460
|
@ -27,7 +27,7 @@ export function loginWithEmail(params) {
|
|||
});
|
||||
}
|
||||
|
||||
export function loginRefresh() {
|
||||
export function refreshCookie() {
|
||||
return request({
|
||||
url: "/login/refresh",
|
||||
method: "post",
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -86,6 +86,9 @@ const initState = {
|
|||
},
|
||||
lang: null,
|
||||
musicQuality: 320000,
|
||||
showGithubIcon: true,
|
||||
showPlaylistsByAppleMusic: true,
|
||||
lastRefreshCookieDate: 0,
|
||||
},
|
||||
};
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"]),
|
||||
|
|
Loading…
Reference in New Issue
Block a user