Skip to content

Commit

Permalink
🔥 Clean code.
Browse files Browse the repository at this point in the history
  • Loading branch information
daihy8759 committed Nov 29, 2020
1 parent 432bc80 commit 095951c
Show file tree
Hide file tree
Showing 51 changed files with 134 additions and 740 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"mobx": "^6.0.4",
"mobx-react-lite": "^3.1.6",
"qrcode": "^1.4.1",
"random-useragent": "^0.3.1",
"react": "^16.9.0",
"react-dom": "^16.9.0",
"react-router-dom": "^5.0.0",
Expand Down
24 changes: 1 addition & 23 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { app, BrowserWindow, Menu, session, shell } from 'electron';
import { app, BrowserWindow, Menu, shell } from 'electron';
import installer, { REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer';
import * as windowStateKeeper from 'electron-window-state';
import * as path from 'path';
import * as agent from 'random-useragent';
import * as url from 'url';
import ipcMainSets from './ipcMainSets';

Expand Down Expand Up @@ -335,27 +334,6 @@ const createWindow = async () => {
win.focus();
} catch (ex) {}
});
// cors
const ieaseUri = 'https://music.163.com';
win.webContents.session.webRequest.onBeforeSendHeaders(
{
urls: [`${ieaseUri}/*`]
},
async (details, callback) => {
const cookie = await session.defaultSession.cookies.get({ url: ieaseUri });
callback({
requestHeaders: {
...details.requestHeaders,
Connection: 'keep-alive',
Referer: ieaseUri,
cookie,
Origin: ieaseUri,
Host: 'music.163.com',
'User-Agent': agent.getRandom()
}
});
}
);
// open devTools
if (process.env.NODE_ENV !== 'production') {
win.webContents.on('did-frame-finish-load', () => {
Expand Down
41 changes: 20 additions & 21 deletions src/renderer/api/artist.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
// @ts-nocheck
import CRYPTO from 'utils/crypto';
import artistList from './common/artists';
import artistDesc from './common/artist_desc';
import artistAlbum from './common/artist_album';
import simiArtist from './common/simi_artist';
import artistSub from './common/artist_sub';
import IArtist from 'interface/IArtist';
import IAlbum from 'interface/IAlbum';
import Api from './';

const { md5 } = CRYPTO;

async function getDesc(id: number) {
try {
const res = await artistDesc({ id });
if (res.data.code !== 200) {
throw res.data;
const { body } = await Api.artist_desc({ id });
if (body.code !== 200) {
throw body;
}
const { briefDesc, introduction } = res.data;
const { briefDesc, introduction } = body;
return {
briefDesc,
introduction
Expand All @@ -31,11 +28,12 @@ async function getDesc(id: number) {

async function getAlbums(id: number) {
try {
const res = await artistAlbum({ id });
if (res.data.code !== 200) {
throw res.data;
const { body } = await Api.artist_album({ id });
if (body.code !== 200) {
throw body;
}
const { hotAlbums } = res.data;
const { hotAlbums } = body;
// @ts-ignore
return hotAlbums.map((e: IAlbum) => ({
id: e.id,
name: e.name,
Expand Down Expand Up @@ -97,11 +95,12 @@ function id2url(id: string) {

async function getArtist(id: number) {
try {
const res = await artistList({ id });
if (res.data.code !== 200) {
throw res.data;
const { body } = await Api.artist_detail({ id });
if (body.code !== 200) {
throw body;
}
const { artist, hotSongs } = res.data;
const { artist, hotSongs } = body;
// @ts-ignore
const songs = hotSongs.map((e: any) => {
const { al, ar } = e;
return {
Expand Down Expand Up @@ -156,8 +155,8 @@ async function getArtist(id: number) {

async function followUser(id: number) {
try {
const res = await artistSub({ id, t: 1 });
if (res.data.code === 200) {
const { body } = await Api.artist_sub({ id, t: 1 });
if (body.code === 200) {
return {
success: false
};
Expand All @@ -170,8 +169,8 @@ async function followUser(id: number) {

async function unFollowUser(id: number) {
try {
const res = await artistSub({ id, t: 0 });
if (res.data.code === 200) {
const { body } = await Api.artist_sub({ id, t: 0 });
if (body.code === 200) {
return {
success: false
};
Expand Down
21 changes: 11 additions & 10 deletions src/renderer/api/comments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import commentMusic from './common/comment_music';
import commentLike from './common/comment_like';
import Api from './';

interface MusicCommentResponse {
newestList?: [];
Expand All @@ -10,19 +9,21 @@ interface MusicCommentResponse {

async function getMusicComments(songId: number, offset = 0): Promise<MusicCommentResponse> {
try {
const res = await commentMusic({
const { body } = await Api.comment_music({
id: songId,
offset
});
if (res.data.code !== 200) {
throw res.data;
if (body.code !== 200) {
throw body;
}
const { data } = res;
return {
newestList: data.comments,
hotList: data.hotComments,
total: data.total,
nextOffset: data.more ? offset + 30 : 0
// @ts-ignore
newestList: body.comments,
// @ts-ignore
hotList: body.hotComments,
// @ts-ignore
total: body.total,
nextOffset: body.more ? offset + 30 : 0
};
} catch (e) {
console.error(e);
Expand Down
9 changes: 0 additions & 9 deletions src/renderer/api/common/album.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/renderer/api/common/album_newest.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/renderer/api/common/artist_album.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/renderer/api/common/artist_desc.ts

This file was deleted.

17 changes: 0 additions & 17 deletions src/renderer/api/common/artist_sub.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/renderer/api/common/artists.ts

This file was deleted.

31 changes: 0 additions & 31 deletions src/renderer/api/common/comment_like.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/renderer/api/common/comment_music.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/renderer/api/common/fm_trash.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/renderer/api/common/follow.ts

This file was deleted.

19 changes: 0 additions & 19 deletions src/renderer/api/common/like.ts

This file was deleted.

21 changes: 0 additions & 21 deletions src/renderer/api/common/login_cellphone.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/renderer/api/common/login_refresh.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/renderer/api/common/login_status.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/renderer/api/common/lyric.ts

This file was deleted.

Loading

0 comments on commit 095951c

Please sign in to comment.