From 459d09b638c466a55d753cff4c873f5c23924adb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BF=AF=E5=A2=A8?= <1362446747@qq.com> Date: Tue, 7 Mar 2023 17:50:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E8=AF=8D=E5=BA=93=E5=AE=8C?= =?UTF-8?q?=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/ipc.js | 35 +++++---- src/pages/index/store.js | 55 ++++++++----- src/pages/index/views/Cookie.vue | 1 + src/pages/index/views/Setting.vue | 22 +++++- src/pages/index/views/Shield.vue | 18 ++++- src/pages/support/views/Video.vue | 2 + src/plugins/axios.js | 126 +++++++++--------------------- src/plugins/headers.js | 33 ++------ src/plugins/socket.js | 3 +- 10 files changed, 142 insertions(+), 155 deletions(-) diff --git a/package.json b/package.json index a29a007..52227d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "material-douden-tool", - "version": "1.2.0", + "version": "1.2.1", "private": true, "author": "濯墨", "scripts": { diff --git a/src/ipc.js b/src/ipc.js index 3bcf756..6bfa027 100644 --- a/src/ipc.js +++ b/src/ipc.js @@ -1,4 +1,4 @@ -import { API, Baidu, Bilibili, Login } from "./plugins/headers"; +import { API, Baidu, Bilibili, Login, MusicQQ } from "./plugins/headers"; import CreateWindow, { AllWindows } from "./background"; import { ipcMain, BrowserWindow, dialog, screen } from "electron"; import { @@ -14,8 +14,7 @@ import { SetUserRoomMode, CheckLogin, GetWebSocket, - SearchMusic163, - SearchMusicQQ, + SearchMusic, SilentUser, GetAuthen, Translate, @@ -24,6 +23,9 @@ import { RemoveSilentUser, GetUserRoomInfo, GetDynamic, + LoginStatistics, + PubShield, + SubShield, } from "./plugins/axios"; import { Stacks } from "./util/Stacks"; import { e, TranslateResult } from "./util/Translate"; @@ -33,6 +35,7 @@ import { Replies } from "./util/Replies"; import FontList from "font-list"; import MD5 from "blueimp-md5"; import OS from "os"; +import Package from "../package.json"; const options = { alwaysOnTop: false, @@ -94,7 +97,7 @@ ipcMain.handle("BilibiliLogin", async () => { return url; }); -ipcMain.handle("Cookie", async (event, cookie, csrf) => { +ipcMain.handle("Cookie", async (event, cookie, csrf, use = true) => { Bilibili.defaults.headers.Cookie = cookie; Login.defaults.headers.Cookie = cookie; Bilibili.defaults.data = { @@ -103,10 +106,14 @@ ipcMain.handle("Cookie", async (event, cookie, csrf) => { rnd: Math.floor(Date.now() / 1000), }; const result = await CheckLogin(); - const equipment = `${OS.platform().toUpperCase()}:${OS.hostname()}`; - const crypto = MD5(`${result.mid}.${equipment}.${csrf}`); - API.defaults.headers.Cookie = `mid=${result.mid}; equipment=${equipment}; crypto=${crypto}`; - return result.avatar; + if (result.mid) { + const hostname = `${OS.platform().toUpperCase()}:${OS.hostname()}`; + const crypto = MD5(`${result.mid}.${hostname}.${csrf}`); + API.defaults.headers.Cookie = `mid=${result.mid}; hostname=${hostname}; crypto=${crypto};`; + await LoginStatistics(result.name, result.avatar, csrf, Package.version); + result.shields = await SubShield(use); + } + return result; }); ipcMain.handle("SearchLive", async (event, keyword) => { @@ -158,11 +165,7 @@ ipcMain.on("ChangeMedal", (event, model_id) => ipcMain.handle("GetMusic", async (event, keyword) => { const match = /\[(\d{1,2}):([0-9.]{1,8})\](.*)\n?/g; - const [music163, musicQQ] = await Promise.all([ - SearchMusic163(keyword), - SearchMusicQQ(keyword), - ]); - const result = [...music163, ...musicQQ]; + const result = await SearchMusic(keyword); for (const item of result) { if (item.lyric && match.test(item.lyric)) { const lyric = []; @@ -282,4 +285,8 @@ ipcMain.handle("GetDynamic", async (event, ids) => { ipcMain.handle("GetFont", async (event) => { const result = await FontList.getFonts(); return result.map((item) => item.replace(/^"|"$/g, "")); -}); \ No newline at end of file +}); + +ipcMain.on("PubShield", PubShield); + +ipcMain.handle("SubShield", (event, use = true) => SubShield(use)); diff --git a/src/pages/index/store.js b/src/pages/index/store.js index 245f295..b4be781 100644 --- a/src/pages/index/store.js +++ b/src/pages/index/store.js @@ -1,6 +1,7 @@ import Vue from "vue"; import Vuex from "vuex"; import { ipcRenderer } from "electron"; +import Socket from "../../plugins/socket"; Vue.use(Vuex); @@ -16,14 +17,43 @@ const shields = JSON.parse(localStorage.getItem("shields")) || []; const stamps = []; stamps[-1] = { lyric: "", tlyric: "" }; +const Handler = { + rooms: (config) => + config.map((item) => ({ + value: item.value, + text: item.text, + uid: item.uid, + avatar: item.avatar, + })), + shields: (config, mid) => + config.filter((item) => !item.mid || item.mid == mid), +}; + +const ChangeConfig = (state, { key, config = [] }) => { + state[key] = [...config]; + const mid = state.cookie.match(/DedeUserID=([^;]+);/); + config = Handler[key] ? Handler[key](config, mid && mid[1]) : config; + localStorage.setItem(key, JSON.stringify(config)); +}; + const ChangeCookie = async (state, cookie) => { - localStorage.setItem("cookie", cookie || ""); - state.cookie = cookie || ""; - if (cookie) { - const bili_jct = cookie.match(/bili_jct=([^;]+);/); - if (bili_jct) { - state.avatar = await ipcRenderer.invoke("Cookie", cookie, bili_jct[1]); + cookie = cookie || ""; + localStorage.setItem("cookie", cookie); + state.cookie = cookie; + const bili_jct = cookie.match(/bili_jct=([^;]+);/); + if (bili_jct) { + const result = await ipcRenderer.invoke( + "Cookie", + cookie, + bili_jct[1], + Socket.UseShareShields + ); + for (const v of state.shields) { + const find = result.shields.find((item) => item.shield === v.shield); + if (!find) result.shields.push(v); } + ChangeConfig(state, { key: "shields", config: result.shields }); + state.avatar = result.avatar; } }; @@ -37,19 +67,6 @@ const ChangeSelect = (state, select = []) => { state.select = select.filter((v) => v); }; -const ChangeConfig = (state, { key, config = [] }) => { - state[key] = [...config]; - if (key === "rooms") { - config = config.map((item) => ({ - value: item.value, - text: item.text, - uid: item.uid, - avatar: item.avatar, - })); - } - localStorage.setItem(key, JSON.stringify(config)); -}; - const ChangeShortcuts = (state, { key, value }) => { const shortcuts = state.shortcuts; if (value) shortcuts[key] = value; diff --git a/src/pages/index/views/Cookie.vue b/src/pages/index/views/Cookie.vue index e5e53ca..fe62070 100644 --- a/src/pages/index/views/Cookie.vue +++ b/src/pages/index/views/Cookie.vue @@ -60,6 +60,7 @@ export default { this.cookie = result.query; this.ChangeCookie(this.cookie); this.Notify("登陆成功"); + this.$router.push("/room") } else if (result.data === -2) { this.code = ""; } diff --git a/src/pages/index/views/Setting.vue b/src/pages/index/views/Setting.vue index 0db5749..12ba3ae 100644 --- a/src/pages/index/views/Setting.vue +++ b/src/pages/index/views/Setting.vue @@ -17,7 +17,7 @@ /> - + Socket[v]), }), methods: { + ...mapMutations(["ChangeConfig"]), ChangeColor(value) { this.$vuetify.theme.themes.light.primary = value; this.$vuetify.theme.themes.dark.primary = value; ipcRenderer.send("Channel", "WindowStyle", value); localStorage.setItem("primary", value); }, - ChangeConfig(config) { + async ChangeSetting(config) { for (const key of Keys) { const value = config.includes(key); Socket[key] = value; localStorage.setItem(key, value); } + const result = await ipcRenderer.invoke( + "SubShield", + config.includes(Keys[4]) + ); + const shields = JSON.parse(localStorage.getItem("shields")) || []; + for (const v of shields) { + const find = result.find((item) => item.shield === v.shield); + if (!find) result.push(v); + } + this.ChangeConfig({ key: "shields", config: result }); }, }, }; diff --git a/src/pages/index/views/Shield.vue b/src/pages/index/views/Shield.vue index be12ad9..f3509fc 100644 --- a/src/pages/index/views/Shield.vue +++ b/src/pages/index/views/Shield.vue @@ -3,7 +3,12 @@ 屏蔽词 @@ -39,6 +44,7 @@ import Pack from "../../../components/Pack.vue"; import DataTable from "../../../components/DataTable.vue"; import { mapMutations, mapState } from "vuex"; +import { ipcRenderer } from "electron"; export default { name: "Shield", @@ -52,7 +58,13 @@ export default { shield: "", handle: "", }), - computed: { ...mapState(["shields"]) }, + computed: { + ...mapState(["shields"]), + mid: ({ $store: { state } }) => { + const mid = state.cookie.match(/DedeUserID=([^;]+);/); + return mid && mid[1]; + }, + }, methods: { ...mapMutations(["ChangeConfig"]), Add() { @@ -65,6 +77,7 @@ export default { } else { find.handle = this.handle; } + ipcRenderer.send("PubShield", this.shield, this.handle, true); this.shield = ""; this.handle = ""; this.ChangeConfig({ key: "shields", config: this.shields }); @@ -73,6 +86,7 @@ export default { const shields = this.shields.filter( (item) => item.shield !== dataset.key ); + ipcRenderer.send("PubShield", dataset.key, "", false); this.ChangeConfig({ key: "shields", config: shields }); }, }, diff --git a/src/pages/support/views/Video.vue b/src/pages/support/views/Video.vue index a9930a2..0fe8fae 100644 --- a/src/pages/support/views/Video.vue +++ b/src/pages/support/views/Video.vue @@ -158,6 +158,8 @@ export default { src.replace(/^data:image\/(png|gif|jpeg);base64,/, "") ); ipcRenderer.send("SaveFiles", datas, Date.now().toString(), "base64"); + this.images = []; + localStorage.setItem("screenshot", JSON.stringify([])); }, Remove({ target: { dataset } }) { const { key } = dataset; diff --git a/src/plugins/axios.js b/src/plugins/axios.js index 80ffec1..2e6eaeb 100644 --- a/src/plugins/axios.js +++ b/src/plugins/axios.js @@ -1,4 +1,4 @@ -import { Baidu, Bilibili, Login, Music163, MusicQQ } from "./headers.js"; +import { Baidu, Bilibili, Login, Music, API } from "./headers.js"; import QS from "qs"; import { BrowserWindow } from "electron"; import { AllWindows } from "../background"; @@ -262,9 +262,9 @@ export const GetFollowLive = async () => { } }; -const GetMusic163Lyric = async (id) => { +const GetMusicLyric = async (id) => { try { - const { lrc, tlyric, yrc, ytlrc } = await Music163.get("/song/lyric", { + const { lrc, tlyric, yrc, ytlrc } = await Music.get("/song/lyric", { params: { id, lv: 1, tv: 1, yv: 1, ytv: 1 }, }); return { @@ -278,15 +278,15 @@ const GetMusic163Lyric = async (id) => { } }; -export const SearchMusic163 = async (keyword) => { +export const SearchMusic = async (keyword) => { try { let { result: { songs }, - } = await Music163.get("/cloudsearch/pc", { - params: { s: keyword, type: 1, limit: 15 }, + } = await Music.get("/cloudsearch/pc", { + params: { s: keyword, type: 1, limit: 20 }, }); songs = songs.map(async ({ name, ar, id, dt, al }) => { - const lyric = await GetMusic163Lyric(id); + const lyric = await GetMusicLyric(id); return { id: `${al.id}-${id}`, name, @@ -303,85 +303,6 @@ export const SearchMusic163 = async (keyword) => { } }; -const GetMusicQQLyric = async (mid) => { - try { - const { lyric = "", trans = "" } = await MusicQQ.get( - "/lyric/fcgi-bin/fcg_query_lyric_new.fcg", - { - baseURL: "https://c.y.qq.com/", - params: { - songmid: mid, - nobase64: 1, - g_tk: 5381, - format: "json", - }, - } - ); - return { lyric, tlyric: trans }; - } catch (error) { - return { lyric: "", tlyric: "" }; - } -}; - -export const SearchMusicQQ = async (keyword) => { - const now = Math.floor(Date.now() / 1000); - try { - let { - request: { - data: { - body: { - song: { list = [] }, - }, - }, - }, - } = await MusicQQ.post("/cgi-bin/musicu.fcg", { - comm: { - cv: 4747474, - ct: 24, - format: "json", - inCharset: "utf-8", - outCharset: "utf-8", - notice: 0, - platform: "yqq.json", - needNewCode: 1, - uin: 0, - g_tk_new_20200303: now, - g_tk: now, - }, - request: { - method: "DoSearchForQQMusicDesktop", - module: "music.search.SearchCgiService", - param: { - remoteplace: "txt.yqq.top", - searchid: "", - search_type: 0, - query: keyword, - page_num: 1, - num_per_page: 15, - }, - }, - }); - list = list.map(async ({ mid, album, name, singer, interval }) => { - const avatar = `https://y.qq.com/music/photo_new/T00${ - album.mid ? 2 : 1 - }R300x300M000${album.mid || singer[0].mid}.jpg?max_age=2592000`; - const lyric = await GetMusicQQLyric(mid); - return { - id: `${album.id}-${mid}`, - name: name, - ...lyric, - singer: singer.map(({ name }) => name).join("/"), - origin: "QQ", - duration: interval * 1000, - avatar, - }; - }); - return await Promise.all(list); - } catch (error) { - return []; - } -}; - export const CheckLogin = async () => { try { const { face, uname, mid } = await Bilibili.get("/x/web-interface/nav", { @@ -391,7 +312,7 @@ export const CheckLogin = async () => { } catch (error) { const win = BrowserWindow.fromId(AllWindows.index); win.webContents.send("CookieOverdue"); - return null; + return { mid: null }; } }; @@ -601,4 +522,33 @@ export const GetVideoInfo = async (key) => { } catch (error) { return { duration: null, avatar: "" }; } -}; \ No newline at end of file +}; + +export const LoginStatistics = async (name, avatar, jct, version) => { + try { + return await API.post("/alogin", { name, avatar, jct, version }); + } catch (error) { + return null; + } +}; + +export const PubShield = async (event, shield, handle, operation = true) => { + try { + return await API.post("/app/add-words", { + shield, + handle, + operation, + }); + } catch (error) { + return false; + } +}; + +export const SubShield = async (use = true) => { + try { + const result = await API.post("/app/get-words", { use }); + return result || []; + } catch (error) { + return []; + } +}; diff --git a/src/plugins/headers.js b/src/plugins/headers.js index a82c839..36130a1 100644 --- a/src/plugins/headers.js +++ b/src/plugins/headers.js @@ -32,7 +32,7 @@ export const Login = axios.create({ }); Login.interceptors.response.use(({ data }) => data); -export const Music163 = axios.create({ +export const Music = axios.create({ baseURL: "https://music.163.com/api/", withCredentials: true, headers: { @@ -42,32 +42,13 @@ export const Music163 = axios.create({ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36", }, }); -Music163.interceptors.response.use(({ data }) => { +Music.interceptors.response.use(({ data }) => { if (data.code !== 200) { throw data; } return data; }); -export const MusicQQ = axios.create({ - baseURL: "https://u.y.qq.com/", - withCredentials: true, - headers: { - origin: "https://y.qq.com/", - referer: "https://y.qq.com/n/ryqq/search", - "User-Agent": - "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36", - Cookie: - "tvfe_boss_uuid=e6e3514d02a59e64; pgv_pvid=3846552470; RK=t2lsTRDoXA; ptcz=bc1ebb324404afaf2e871630fcc04498f3170e9a5f7a801993b9d399ba0ac44e; o_cookie=1362446747; pac_uid=1_1362446747; iip=0; fqm_pvqid=0f43dbab-37c7-4a1b-b09a-d1b97d32b8c1; ts_refer=www.google.com.hk/; ts_uid=8123348496; tmeLoginType=2; ptui_loginuin=1078433231; fqm_sessionid=c0d1a292-15f4-4d84-82e5-88f1c0d10faf; pgv_info=ssid=s291314040; ts_last=y.qq.com/n/ryqq/search; _qpsvr_localtk=0.7171941336146996; login_type=1; wxunionid=; euin=NKEsoicl7w-F; psrf_qqunionid=57409FB062EBB1FDF61F37076EDC3A52; psrf_access_token_expiresAt=1685417107; psrf_qqopenid=9ADFA0286AA69C06D5A50E2371AA495B; qm_keyst=Q_H_L_5ZJkAbWKejqD9CpJ9gPF0Vp_zwsS5Y-n1vbO0k2N-GdAAwywTJMCupw; uin=996387628; wxrefresh_token=; psrf_qqrefresh_token=6EBCA2FFBDA2D85A62E3E08C8B45070F; qqmusic_key=Q_H_L_5ZJkAbWKejqD9CpJ9gPF0Vp_zwsS5Y-n1vbO0k2N-GdAAwywTJMCupw; psrf_qqaccess_token=1FDFCBAEAFE19C5ECDC440028997BBF3; qm_keyst=Q_H_L_5ZJkAbWKejqD9CpJ9gPF0Vp_zwsS5Y-n1vbO0k2N-GdAAwywTJMCupw; psrf_musickey_createtime=1677641107; wxopenid=", - }, -}); -MusicQQ.interceptors.response.use(({ data }) => { - if (data.code !== 0) { - throw data; - } - return data; -}); - export const Baidu = axios.create({ baseURL: "https://fanyi.baidu.com/", withCredentials: true, @@ -93,16 +74,16 @@ Baidu.interceptors.response.use(({ data }) => { }); export const API = axios.create({ - baseURL: "http://api.hustmaths.top/", + baseURL: "http://pp_backend_2023_3.commonwind.top/", withCredentials: true, headers: { - origin: "http://api.hustmaths.top/", - referer: "http://api.hustmaths.top/", + origin: "http://pp_backend_2023_3.commonwind.top/", + referer: "http://pp_backend_2023_3.commonwind.top/", }, }); API.interceptors.response.use(({ data }) => { - if (data.status !== 200) { + if (data.code !== 200) { throw data; } - return data; + return data.data; }); diff --git a/src/plugins/socket.js b/src/plugins/socket.js index 0e3e327..2cb4f24 100644 --- a/src/plugins/socket.js +++ b/src/plugins/socket.js @@ -56,8 +56,9 @@ export default class Socket { static AutoChangeMedal = localStorage.getItem("AutoChangeMedal") !== "false"; static AutoCopyForbidWord = localStorage.getItem("AutoCopyForbidWord") !== "false"; + static UseShareShields = localStorage.getItem("UseShareShields") !== "false"; constructor(host) { - this.roomid =host. roomid; + this.roomid = host.roomid; this.token = host.token; this.timer = null; this.admin = host.admin;