Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 0 additions & 41 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"autoprefixer": "^10.4.13",
"axios": "^1.1.3",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"next-auth": "^4.16.4",
Expand Down
10 changes: 2 additions & 8 deletions pages/api/addTracks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios'

const Handler = async (req: NextApiRequest, res: NextApiResponse) => {
const body = req.body
Expand All @@ -25,15 +24,10 @@ const Handler = async (req: NextApiRequest, res: NextApiResponse) => {
}

const addTracks = async(headers: {[key: string]: string}, playListId: string, uris: string[]) => {
const data = {
uris: uris,
}

const response = await axios({
const response = await fetch(`https://api.spotify.com/v1/playlists/${playListId}/tracks`, {
method: 'POST',
url: `https://api.spotify.com/v1/playlists/${playListId}/tracks`,
headers: headers,
data: data
body: JSON.stringify({ uris: uris }),
})

return response
Expand Down
19 changes: 10 additions & 9 deletions pages/api/eachTrack.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios'

const EachTrack = async (req: NextApiRequest, res: NextApiResponse) => {
const body = req.body
Expand All @@ -20,16 +19,18 @@ const getTrackId = async (token: any, ids: any, artistId: string) => {

for (const id of ids) {
const severalId = id.join(',')
const response = await axios.get(`https://api.spotify.com/v1/albums`, {
params: {
'ids': severalId,
},
const params = new URLSearchParams({
'ids': severalId,
})

const response = await fetch(`https://api.spotify.com/v1/albums?${params}`, {
headers: {
Authorization: `Bearer ${token}`
}
})
Authorization: `Bearer ${token}`
}
})

albums = albums.concat(response.data.albums)
const data = await response.json()
albums = albums.concat(data.albums)
if (response.status != 200) {
status = response.status
break
Expand Down
29 changes: 12 additions & 17 deletions pages/api/playList.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,25 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios'

const Playlist = async (req: NextApiRequest, res: NextApiResponse) => {
const body = req.body
const id = body.id
const playlistName = body.name

const headers = {
Authorization: `Bearer ${body.token}`,
'Content-Type': 'application/json; charset=utf-8',
}

const data = {
name: playlistName,
description: 'Playlist created by Srive',
public: false,
}

const response = await axios({
const response = await fetch(`https://api.spotify.com/v1/users/${id}/playlists`, {
method: 'POST',
url: `https://api.spotify.com/v1/users/${id}/playlists`,
headers: headers,
data: data
headers: {
Authorization: `Bearer ${body.token}`,
'Content-Type': 'application/json; charset=utf-8',
},
body: JSON.stringify({
name: playlistName,
description: 'Playlist created by Srive',
public: false,
}),
})

res.status(response.status).json({ data: response.data })
const data = await response.json()
res.status(response.status).json({ data: data })
}

export default Playlist
22 changes: 11 additions & 11 deletions pages/api/search.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const body = req.body
Expand All @@ -8,16 +7,17 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}

async function searchSpotify(token: string, artistName: string) {
const response = await axios.get('https://api.spotify.com/v1/search', {
params: {
'query': artistName,
'type': 'artist',
'locale': 'ja'
},
const params = new URLSearchParams({
'query': artistName,
'type': 'artist',
'locale': 'ja'
})

const response = await fetch(`https://api.spotify.com/v1/search?${params}`, {
headers: {
Authorization: `Bearer ${token}`
}
})
Authorization: `Bearer ${token}`
}
})

return response
return { status: response.status, data: await response.json() }
}
20 changes: 10 additions & 10 deletions pages/api/tracks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { NextApiRequest, NextApiResponse } from 'next'
import axios from 'axios'

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const body = req.body
Expand All @@ -18,15 +17,16 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}

async function getTracks(token: string, id: string, groups: string = 'album,single') {
const response = await axios.get(`https://api.spotify.com/v1/artists/${id}/albums`, {
params: {
'include_groups': groups,
'limit': 50,
},
const params = new URLSearchParams({
'include_groups': groups,
'limit': '50',
})

const response = await fetch(`https://api.spotify.com/v1/artists/${id}/albums?${params}`, {
headers: {
Authorization: `Bearer ${token}`
}
})
Authorization: `Bearer ${token}`
}
})

return response
return { status: response.status, data: await response.json() }
}
Loading