mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-11 17:42:48 +00:00
audio clips - client done
This commit is contained in:
@@ -1,19 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Navbar } from './components/Navbar/Navbar.component';
|
import { Navbar } from './components/Navbar';
|
||||||
|
|
||||||
//styling
|
//styling
|
||||||
import './scss/index.scss';
|
import './scss/index.scss';
|
||||||
|
|
||||||
interface Props {
|
export class Wrapper extends React.Component<any, any> {
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
interface State {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export class Wrapper extends React.Component<Props, State> {
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -22,9 +13,7 @@ export class Wrapper extends React.Component<Props, State> {
|
|||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Navbar />
|
<Navbar />
|
||||||
<div>
|
<div>{this.props.children}</div>
|
||||||
{this.props.children}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { Soundboard } from './pages/Soundboard/Soundboard';
|
|||||||
import { NotFound } from './pages/NotFound/NotFound';
|
import { NotFound } from './pages/NotFound/NotFound';
|
||||||
import { Downloader } from './pages/Downloader/Downloader';
|
import { Downloader } from './pages/Downloader/Downloader';
|
||||||
import { Pubg } from './pages/Pubg/Pubg';
|
import { Pubg } from './pages/Pubg/Pubg';
|
||||||
|
import { Clips } from './pages/Clips';
|
||||||
|
|
||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<Router history={browserHistory}>
|
<Router history={browserHistory}>
|
||||||
@@ -16,6 +17,7 @@ ReactDOM.render(
|
|||||||
<Route path="/soundboard" component={Soundboard}/>
|
<Route path="/soundboard" component={Soundboard}/>
|
||||||
<Route path="/downloader" component={Downloader}/>
|
<Route path="/downloader" component={Downloader}/>
|
||||||
<Route path="/pubg" component={Pubg}/>
|
<Route path="/pubg" component={Pubg}/>
|
||||||
|
<Route path="/clips" component={Clips}/>
|
||||||
<Route path="*" component={NotFound}/>
|
<Route path="*" component={NotFound}/>
|
||||||
</Route>
|
</Route>
|
||||||
</Router>
|
</Router>
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class Navbar extends React.Component<Props, State> {
|
|||||||
<Link to="/soundboard" className="Navbar__item" activeClassName="Navbar__item--active">Soundboard</Link>
|
<Link to="/soundboard" className="Navbar__item" activeClassName="Navbar__item--active">Soundboard</Link>
|
||||||
<Link to="/downloader" className="Navbar__item" activeClassName="Navbar__item--active">Youtube Downloader</Link>
|
<Link to="/downloader" className="Navbar__item" activeClassName="Navbar__item--active">Youtube Downloader</Link>
|
||||||
<Link to="/pubg" className="Navbar__item" activeClassName="Navbar__item--active">Pubg</Link>
|
<Link to="/pubg" className="Navbar__item" activeClassName="Navbar__item--active">Pubg</Link>
|
||||||
|
<Link to="/clips" className="Navbar__item" activeClassName="Navbar__item--active">Clips</Link>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
1
client/app/components/Navbar/index.ts
Normal file
1
client/app/components/Navbar/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './Navbar';
|
||||||
@@ -1,54 +1,32 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import axios from 'axios';
|
|
||||||
|
|
||||||
import './SoundList.scss';
|
import './SoundList.scss';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
soundList: SoundType[];
|
||||||
|
type: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
showAudioControls: boolean[];
|
showAudioControls: boolean[];
|
||||||
soundList: {
|
}
|
||||||
|
|
||||||
|
export interface SoundType {
|
||||||
extension: string;
|
extension: string;
|
||||||
name: string;
|
name: string;
|
||||||
prefix: string;
|
prefix?: string;
|
||||||
}[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SoundList extends React.Component<Props, State> {
|
export class SoundList extends React.Component<Props, State> {
|
||||||
|
|
||||||
private soundListCache: any;
|
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
soundList: [],
|
|
||||||
showAudioControls: [],
|
showAudioControls: [],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
this.getSoundList();
|
|
||||||
}
|
|
||||||
|
|
||||||
getSoundList() {
|
|
||||||
if (!this.soundListCache) {
|
|
||||||
axios.get("/soundlist").then((response) => {
|
|
||||||
this.soundListCache = response.data;
|
|
||||||
this.setState({
|
|
||||||
soundList: response.data,
|
|
||||||
});
|
|
||||||
}).catch(() => {
|
|
||||||
//console.warn(error.response.data);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.setState({
|
|
||||||
soundList: this.soundListCache,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
checkExtension(extension: string) {
|
checkExtension(extension: string) {
|
||||||
switch(extension) {
|
switch(extension) {
|
||||||
case "wav":
|
case "wav":
|
||||||
@@ -72,26 +50,27 @@ export class SoundList extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
||||||
|
const { soundList, type } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="Card">
|
<div className="Card">
|
||||||
<div className="Card__header" style={{display:'flex'}}>
|
<div className="Card__header" style={{display:'flex'}}>
|
||||||
<div>
|
<div>
|
||||||
Sounds
|
<span>{type}</span>
|
||||||
<i className="fa fa fa-volume-up" aria-hidden="true"/>
|
<i className="fa fa fa-volume-up" aria-hidden="true"/>
|
||||||
</div>
|
</div>
|
||||||
<div style={{flex:1}}/>
|
<div style={{flex:1}}/>
|
||||||
<div>({this.state.soundList.length})</div>
|
<div>({soundList.length})</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{this.state.soundList.length > 0 ? this.state.soundList.map((sound, index) => {
|
{soundList.length > 0 ? soundList.map((sound: SoundType, index: number) => {
|
||||||
return (
|
return (
|
||||||
<div key={index} className="SoundList__item">
|
<div key={index} className="SoundList__item">
|
||||||
<div>
|
<div>{(sound.prefix || '') + sound.name}</div>
|
||||||
{sound.prefix + sound.name}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{this.checkExtension(sound.extension) && this.state.showAudioControls[index] ?
|
{this.checkExtension(sound.extension) && this.state.showAudioControls[index] ?
|
||||||
<audio controls src={"/public/sounds/" + sound.name + "." + sound.extension}
|
<audio controls src={`/public/${type.toLowerCase()}/` + sound.name + "." + sound.extension}
|
||||||
itemType={"audio/" + sound.extension}
|
itemType={"audio/" + sound.extension}
|
||||||
style={{width: "100px"}}/>
|
style={{width: "100px"}}/>
|
||||||
: <i className="fa fa-play link" aria-hidden="true" onClick={() => this.handleShowAudio(index)}/> }
|
: <i className="fa fa-play link" aria-hidden="true" onClick={() => this.handleShowAudio(index)}/> }
|
||||||
1
client/app/components/SoundList/index.ts
Normal file
1
client/app/components/SoundList/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './SoundList';
|
||||||
46
client/app/pages/Clips/Clips.tsx
Normal file
46
client/app/pages/Clips/Clips.tsx
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
import { SoundList, SoundType } from '../../components/SoundList';
|
||||||
|
|
||||||
|
interface Props {}
|
||||||
|
|
||||||
|
interface State {
|
||||||
|
clipList: SoundType[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export class Clips extends React.Component<Props, State> {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.state = {
|
||||||
|
clipList: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
this.getClipList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getClipList() {
|
||||||
|
axios
|
||||||
|
.get('/api/cliplist')
|
||||||
|
.then(response => {
|
||||||
|
this.setState({
|
||||||
|
clipList: response.data,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error: any) => {
|
||||||
|
console.error(error.response.data);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<div className="Soundboard">
|
||||||
|
<div className="column">
|
||||||
|
<SoundList soundList={this.state.clipList} type="Clips"/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
1
client/app/pages/Clips/index.ts
Normal file
1
client/app/pages/Clips/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './Clips';
|
||||||
@@ -48,7 +48,7 @@ export class Downloader extends React.Component<Props, State> {
|
|||||||
dataLoading: true,
|
dataLoading: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
axios.get(`/ytdownloader`, {
|
axios.get(`/api/ytdownloader`, {
|
||||||
params: {
|
params: {
|
||||||
fileType: this.state.fileType,
|
fileType: this.state.fileType,
|
||||||
url: this.state.url,
|
url: this.state.url,
|
||||||
@@ -81,14 +81,6 @@ export class Downloader extends React.Component<Props, State> {
|
|||||||
value={this.state.url}
|
value={this.state.url}
|
||||||
onChange={(event) => this.setState({url: event.target.value})}/>
|
onChange={(event) => this.setState({url: event.target.value})}/>
|
||||||
|
|
||||||
{/*<div style={{marginBottom:'10px'}}>
|
|
||||||
<button className={"button Downloader__button" + (this.state.fileType === "mp3" ? " button--primary" : "")}
|
|
||||||
onClick={() => this.setState({fileType:"mp3"})}>mp3</button>
|
|
||||||
<button className={"button Downloader__button" + (this.state.fileType=== "mp4" ? " button--primary" : "")}
|
|
||||||
onClick={() => this.setState({fileType:"mp4"})}>mp4</button>
|
|
||||||
</div>*/}
|
|
||||||
|
|
||||||
|
|
||||||
<div style={{marginBottom:'10px'}}>
|
<div style={{marginBottom:'10px'}}>
|
||||||
<button className="button button--primary"
|
<button className="button button--primary"
|
||||||
style={{width: '100px', height: '40px', fontSize: 'large'}}
|
style={{width: '100px', height: '40px', fontSize: 'large'}}
|
||||||
|
|||||||
@@ -19,10 +19,26 @@ export class Home extends React.Component<Props, State> {
|
|||||||
<div className="Card__header">
|
<div className="Card__header">
|
||||||
Go Discord Bot
|
Go Discord Bot
|
||||||
</div>
|
</div>
|
||||||
|
<h3>Audio Clipping</h3>
|
||||||
|
<p><em>NEW:</em> Audio clipping now supported! Try it out with the <code>clip</code> command!</p>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<h3>PUBG Stats</h3>
|
||||||
|
<p>PUBG stats are pulled from the score API.</p>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<h3>Youtube Downloader</h3>
|
||||||
|
<p>Convert Youtube URL's to MP3 files.</p>
|
||||||
|
|
||||||
|
<br/>
|
||||||
|
|
||||||
|
<h3>Soundboard Upload</h3>
|
||||||
<p>Drag and drop files to upload. Sounds can be played in discord by typing the commands on the next page.</p>
|
<p>Drag and drop files to upload. Sounds can be played in discord by typing the commands on the next page.</p>
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
<p>Gif command now supported! Example: !gif awesome cat gifs</p>
|
|
||||||
<br/>
|
|
||||||
<p>Check out the source code on
|
<p>Check out the source code on
|
||||||
<a href="https://github.com/mgerb/GoBot" target="_blank"> GitHub
|
<a href="https://github.com/mgerb/GoBot" target="_blank"> GitHub
|
||||||
<i className="fa fa-github" aria-hidden="true"/>
|
<i className="fa fa-github" aria-hidden="true"/>
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class Pubg extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
axios.get("/stats/pubg").then((res) => {
|
axios.get("/api/stats/pubg").then((res) => {
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
players: _.map(res.data) as any,
|
players: _.map(res.data) as any,
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import Dropzone from 'react-dropzone';
|
import Dropzone from 'react-dropzone';
|
||||||
import axios, { AxiosRequestConfig } from 'axios';
|
import axios, { AxiosRequestConfig } from 'axios';
|
||||||
|
|
||||||
import { SoundList } from './SoundList.component';
|
import { SoundList, SoundType } from '../../components/SoundList';
|
||||||
|
|
||||||
import './Soundboard.scss';
|
import './Soundboard.scss';
|
||||||
|
|
||||||
@@ -17,12 +17,13 @@ interface State {
|
|||||||
password: string;
|
password: string;
|
||||||
uploaded: boolean;
|
uploaded: boolean;
|
||||||
uploadError: string;
|
uploadError: string;
|
||||||
|
soundList: SoundType[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Soundboard extends React.Component<Props, State> {
|
export class Soundboard extends React.Component<Props, State> {
|
||||||
|
|
||||||
private config: AxiosRequestConfig;
|
private config: AxiosRequestConfig;
|
||||||
public refs: any;
|
private soundListCache: any;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@@ -31,6 +32,7 @@ export class Soundboard extends React.Component<Props, State> {
|
|||||||
password: "",
|
password: "",
|
||||||
uploaded: false,
|
uploaded: false,
|
||||||
uploadError: " ",
|
uploadError: " ",
|
||||||
|
soundList: [],
|
||||||
},
|
},
|
||||||
|
|
||||||
self = this;
|
self = this;
|
||||||
@@ -47,6 +49,25 @@ export class Soundboard extends React.Component<Props, State> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.getSoundList();
|
||||||
|
}
|
||||||
|
|
||||||
|
private getSoundList() {
|
||||||
|
if (!this.soundListCache) {
|
||||||
|
axios.get("/api/soundlist").then((response) => {
|
||||||
|
this.soundListCache = response.data;
|
||||||
|
this.setState({
|
||||||
|
soundList: response.data,
|
||||||
|
});
|
||||||
|
}).catch((error: any) => {
|
||||||
|
console.error(error.response.data);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.setState({
|
||||||
|
soundList: this.soundListCache,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onDrop(acceptedFiles: any) {
|
onDrop(acceptedFiles: any) {
|
||||||
@@ -61,7 +82,7 @@ export class Soundboard extends React.Component<Props, State> {
|
|||||||
formData.append("file", file);
|
formData.append("file", file);
|
||||||
formData.append("password", this.state.password);
|
formData.append("password", this.state.password);
|
||||||
|
|
||||||
axios.put("/upload", formData, this.config)
|
axios.put("/api/upload", formData, this.config)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({
|
this.setState({
|
||||||
password: "",
|
password: "",
|
||||||
@@ -70,9 +91,8 @@ export class Soundboard extends React.Component<Props, State> {
|
|||||||
uploadError: " ",
|
uploadError: " ",
|
||||||
});
|
});
|
||||||
|
|
||||||
// reset sound list cache and load the new list
|
this.soundListCache = undefined;
|
||||||
this.refs.SoundList.soundListCache = undefined;
|
this.getSoundList();
|
||||||
this.refs.SoundList.getSoundList();
|
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
percentCompleted: 0,
|
percentCompleted: 0,
|
||||||
@@ -89,10 +109,11 @@ export class Soundboard extends React.Component<Props, State> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { soundList } = this.state;
|
||||||
return (
|
return (
|
||||||
<div className="Soundboard">
|
<div className="Soundboard">
|
||||||
<div className="column">
|
<div className="column">
|
||||||
<SoundList ref="SoundList"/>
|
<SoundList soundList={soundList} type="Sounds"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="column">
|
<div className="column">
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
"Token": "",
|
"Token": "",
|
||||||
"BotPrefix": "#",
|
"BotPrefix": "#",
|
||||||
"SoundsPath": "./sounds/",
|
"SoundsPath": "./sounds/",
|
||||||
|
"ClipsPath": "./clips/",
|
||||||
"UploadPassword": "",
|
"UploadPassword": "",
|
||||||
"ServerAddr": ":80",
|
"ServerAddr": ":80",
|
||||||
"pubg": {
|
"pubg": {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ const (
|
|||||||
|
|
||||||
sampleRate int = 96000 // rate at which wav writer need to make audio up to speed
|
sampleRate int = 96000 // rate at which wav writer need to make audio up to speed
|
||||||
voiceClipQueuePacketSize int = 2000 // this packet size equates to roughly 40 seconds of audio
|
voiceClipQueuePacketSize int = 2000 // this packet size equates to roughly 40 seconds of audio
|
||||||
voiceClipDirectory string = "./clips"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// store our connection objects in a map tied to a guild id
|
// store our connection objects in a map tied to a guild id
|
||||||
@@ -292,13 +291,13 @@ func (conn *audioConnection) clipAudio(m *discordgo.MessageCreate) {
|
|||||||
func writePacketsToFile(username string, packets chan *discordgo.Packet) {
|
func writePacketsToFile(username string, packets chan *discordgo.Packet) {
|
||||||
|
|
||||||
// create clips folder if it does not exist
|
// create clips folder if it does not exist
|
||||||
if _, err := os.Stat(voiceClipDirectory); os.IsNotExist(err) {
|
if _, err := os.Stat(config.Config.ClipsPath); os.IsNotExist(err) {
|
||||||
os.Mkdir(voiceClipDirectory, os.ModePerm)
|
os.Mkdir(config.Config.ClipsPath, os.ModePerm)
|
||||||
}
|
}
|
||||||
|
|
||||||
// construct filename
|
// construct filename
|
||||||
timestamp := time.Now().UTC().Format("2006-01-02") + "-" + strconv.Itoa(int(time.Now().Unix()))
|
timestamp := time.Now().UTC().Format("2006-01-02") + "-" + strconv.Itoa(int(time.Now().Unix()))
|
||||||
wavOut, err := os.Create(voiceClipDirectory + "/" + timestamp + "-" + username + ".wav")
|
wavOut, err := os.Create(config.Config.ClipsPath + timestamp + "-" + username + ".wav")
|
||||||
|
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
defer wavOut.Close()
|
defer wavOut.Close()
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ type configFile struct {
|
|||||||
Token string `json:"Token"`
|
Token string `json:"Token"`
|
||||||
BotPrefix string `json:"BotPrefix"` //prefix to use for bot commands
|
BotPrefix string `json:"BotPrefix"` //prefix to use for bot commands
|
||||||
SoundsPath string `json:"SoundsPath"`
|
SoundsPath string `json:"SoundsPath"`
|
||||||
|
ClipsPath string `json:"ClipsPath"`
|
||||||
UploadPassword string `json:"UploadPassword"`
|
UploadPassword string `json:"UploadPassword"`
|
||||||
ServerAddr string `json:"ServerAddr`
|
ServerAddr string `json:"ServerAddr`
|
||||||
Pubg struct {
|
Pubg struct {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package handlers
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"net/http"
|
"net/http"
|
||||||
@@ -58,3 +59,31 @@ func PopulateSoundList() error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ClipList -
|
||||||
|
func ClipList(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
|
clipList := []sound{}
|
||||||
|
|
||||||
|
files, err := ioutil.ReadDir(config.Config.ClipsPath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
response.ERR(w, 500, response.DefaultInternalError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, f := range files {
|
||||||
|
fileName := strings.Split(f.Name(), ".")[0]
|
||||||
|
extension := strings.Split(f.Name(), ".")[1]
|
||||||
|
|
||||||
|
listItem := sound{
|
||||||
|
Name: fileName,
|
||||||
|
Extension: extension,
|
||||||
|
}
|
||||||
|
|
||||||
|
clipList = append(clipList, listItem)
|
||||||
|
}
|
||||||
|
|
||||||
|
response.JSON(w, clipList)
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,18 +30,22 @@ func getRouter() *chi.Mux {
|
|||||||
workDir, _ := os.Getwd()
|
workDir, _ := os.Getwd()
|
||||||
|
|
||||||
FileServer(r, "/static", http.Dir(filepath.Join(workDir, "./dist/static")))
|
FileServer(r, "/static", http.Dir(filepath.Join(workDir, "./dist/static")))
|
||||||
FileServer(r, "/public/sounds", http.Dir(filepath.Join(workDir, "./sounds")))
|
FileServer(r, "/public/sounds", http.Dir(filepath.Join(workDir, config.Config.SoundsPath)))
|
||||||
FileServer(r, "/public/youtube", http.Dir(filepath.Join(workDir, "./youtube")))
|
FileServer(r, "/public/youtube", http.Dir(filepath.Join(workDir, "./youtube")))
|
||||||
|
FileServer(r, "/public/clips", http.Dir(filepath.Join(workDir, config.Config.ClipsPath)))
|
||||||
|
|
||||||
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
r.NotFound(func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.ServeFile(w, r, "./dist/index.html")
|
http.ServeFile(w, r, "./dist/index.html")
|
||||||
})
|
})
|
||||||
|
|
||||||
// configure end points
|
r.Route("/api", func(r chi.Router) {
|
||||||
|
// configure api end points
|
||||||
r.Get("/soundlist", handlers.SoundList)
|
r.Get("/soundlist", handlers.SoundList)
|
||||||
|
r.Get("/cliplist", handlers.ClipList)
|
||||||
r.Put("/upload", handlers.FileUpload)
|
r.Put("/upload", handlers.FileUpload)
|
||||||
r.Get("/ytdownloader", handlers.Downloader)
|
r.Get("/ytdownloader", handlers.Downloader)
|
||||||
r.Get("/stats/pubg", pubg.Handler)
|
r.Get("/stats/pubg", pubg.Handler)
|
||||||
|
})
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user