setUrl(e.target.value)}
+ onChange={setInputYoutubeUrl}
type="text"
- value={url}
+ value={disc.youtubeUrl || ""}
/>
diff --git a/client/src/store/discs.ts b/client/src/store/discs.ts
index b1a776c..be1c0d4 100644
--- a/client/src/store/discs.ts
+++ b/client/src/store/discs.ts
@@ -3,7 +3,8 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
export interface Disc {
title?: string
description?: string
- audioUrl?: string
+ youtubeUrl?: string
+ resourceName: string
defaultTitle: string
defaultDescription: string
icon: string
@@ -18,58 +19,72 @@ const defaultTitle = "Music Disc"
const initialState: DiscsState = {
discs: [
{
+ resourceName: "13",
defaultTitle, defaultDescription: "C418 - 13",
icon: "/sprites/music_disc_13.png"
},
{
+ resourceName: "cat",
defaultTitle, defaultDescription: "C418 - cat",
icon: "/sprites/music_disc_cat.png"
},
{
+ resourceName: "blocks",
defaultTitle, defaultDescription: "C418 - blocks",
icon: "/sprites/music_disc_blocks.png"
},
{
+ resourceName: "chirp",
defaultTitle, defaultDescription: "C418 - chirp",
icon: "/sprites/music_disc_chirp.png"
},
{
+ resourceName: "far",
defaultTitle, defaultDescription: "C418 - far",
icon: "/sprites/music_disc_far.png"
},
{
+ resourceName: "mall",
defaultTitle, defaultDescription: "C418 - mall",
icon: "/sprites/music_disc_mall.png"
},
{
+ resourceName: "mellohi",
defaultTitle, defaultDescription: "C418 - mellohi",
icon: "/sprites/music_disc_mellohi.png"
},
{
+ resourceName: "stal",
defaultTitle, defaultDescription: "C418 - stal",
icon: "/sprites/music_disc_stal.png"
},
{
+ resourceName: "strad",
defaultTitle, defaultDescription: "C418 - strad",
icon: "/sprites/music_disc_strad.png"
},
{
+ resourceName: "ward",
defaultTitle, defaultDescription: "C418 - ward",
icon: "/sprites/music_disc_ward.png"
},
{
+ resourceName: "11",
defaultTitle, defaultDescription: "C418 - 11",
icon: "/sprites/music_disc_11.png"
},
{
+ resourceName: "wait",
defaultTitle, defaultDescription: "C418 - wait",
icon: "/sprites/music_disc_wait.png"
},
{
+ resourceName: "otherside",
defaultTitle, defaultDescription: "Lena Raine - otherside",
icon: "/sprites/music_disc_otherside.png"
},
{
+ resourceName: "pigstep",
defaultTitle, defaultDescription: "Lena Raine - Pigstep",
icon: "/sprites/music_disc_pigstep.png"
},
@@ -80,21 +95,21 @@ export const discsSlice = createSlice({
name: "discs",
initialState,
reducers: {
- setTitle: (state, action: PayloadAction<{ id: number, title: string }>) => {
+ setTitle: (state, action: PayloadAction<{ id: number, title: string|undefined }>) => {
const { id, title } = action.payload;
state.discs[id].title = title
},
- setDescription: (state, action: PayloadAction<{ id: number, description: string }>) => {
+ setDescription: (state, action: PayloadAction<{ id: number, description: string|undefined }>) => {
const { id, description } = action.payload;
state.discs[id].description = description
},
- setAudioUrl: (state, action: PayloadAction<{ id: number, audioUrl: string }>) => {
- const { id, audioUrl } = action.payload;
- state.discs[id].audioUrl = audioUrl
+ setYoutubeUrl: (state, action: PayloadAction<{ id: number, youtubeUrl: string|undefined }>) => {
+ const { id, youtubeUrl } = action.payload;
+ state.discs[id].youtubeUrl = youtubeUrl
}
}
})
-export const { setTitle, setDescription, setAudioUrl } = discsSlice.actions
+export const { setTitle, setDescription, setYoutubeUrl } = discsSlice.actions
export default discsSlice.reducer
diff --git a/src/index.ts b/src/index.ts
index 5df7281..3e344e1 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -3,7 +3,7 @@ import ytdl from "ytdl-core"
import Joi from "joi"
import JSZip from "jszip"
import ffmpeg from "fluent-ffmpeg"
-import { createWriteStream, readFileSync } from "fs"
+import { readFileSync } from "fs"
import temp from "temp"
const availableDiscs = [
@@ -13,7 +13,7 @@ const availableDiscs = [
interface Disc {
title?: string
description?: string
- youtubeUrl: string
+ youtubeUrl?: string
}
interface CreatePackPayload {
@@ -73,7 +73,7 @@ function addCreateRoute(server: hapi.Server) {
const discValidator = Joi.object({
title: Joi.string().optional(),
description: Joi.string().optional(),
- youtubeUrl: Joi.string().required(),
+ youtubeUrl: Joi.string().optional(),
}).optional()
const discsValidators: Record> = {}
@@ -93,6 +93,7 @@ function addCreateRoute(server: hapi.Server) {
validate: { payload: payloadValidator }
},
handler: async (req, h) => {
+ console.log("CREATE")
const payload = req.payload as CreatePackPayload
const zip = JSZip();
@@ -117,7 +118,7 @@ function addCreateRoute(server: hapi.Server) {
audioStreams.push(new Promise(async (resolve, reject) => {
const tempFile = temp.path()
try {
- await dowloadYoutubeAudio(url, tempFile)
+ await dowloadYoutubeAudio(url as string, tempFile)
} catch (e) {
console.error(e)
reject(e)
@@ -163,8 +164,11 @@ function addCreateRoute(server: hapi.Server) {
async function main() {
const server = hapi.server({
- port: 3000,
+ port: process.env.PORT || 3000,
host: 'localhost',
+ routes: {
+ cors: true
+ }
})
addGetTitleRoute(server)