Merge branch 'master' of ssh://git.andreafazzi.eu:10022/andrea/youtube-dl-service
This commit is contained in:
commit
fa19e166d7
10 changed files with 108 additions and 1817 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
.log/
|
||||
**/*~
|
||||
/node_modules/
|
||||
/public/build/
|
||||
|
|
1
backend/.gitignore
vendored
1
backend/.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
backend
|
||||
youtube-dl-service
|
||||
|
||||
|
|
|
@ -96,9 +96,8 @@ func getToken(config *Config, password string) ([]byte, error) {
|
|||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims(claims))
|
||||
|
||||
/* Sign the token with our secret */
|
||||
tokenString, err := token.SignedString(config.JWTSigningKey)
|
||||
tokenString, err := token.SignedString([]byte(config.JWTSigningKey))
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -44,16 +44,16 @@ func (t *testSuite) BeforeAll() {
|
|||
// Test the creation of a new task. A new task is created with a POST
|
||||
// request to the endpoint.
|
||||
func (t *testSuite) TestCreateTask() {
|
||||
video, err := postTask("https://www.youtube.com/watch?v=AVIBLFl28vo")
|
||||
video, err := postTask("https://www.youtube.com/watch?v=zGDzdps75ns")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
t.Equal("AVIBLFl28vo", video.ID)
|
||||
t.Equal("zGDzdps75ns", video.ID)
|
||||
}
|
||||
|
||||
// Test the response of a GET /tasks/:id requests.
|
||||
func (t *testSuite) TestGetTask() {
|
||||
video, err := postTask("https://www.youtube.com/watch?v=AVIBLFl28vo")
|
||||
video, err := postTask("https://www.youtube.com/watch?v=zGDzdps75ns")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -83,7 +83,7 @@ func (t *testSuite) TestGetTask() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
t.Equal("AVIBLFl28vo", ts.ID)
|
||||
t.Equal("zGDzdps75ns", video.ID)
|
||||
t.Equal(task.StatusCompleted, ts.Status)
|
||||
}
|
||||
|
||||
|
|
1
frontend/.gitignore
vendored
1
frontend/.gitignore
vendored
|
@ -1 +1,2 @@
|
|||
config.js
|
||||
node_modules/
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because one or more lines are too long
|
@ -1,45 +1,13 @@
|
|||
<script>
|
||||
export let url;
|
||||
export let endpoint;
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte'
|
||||
|
||||
export let endpoint: string
|
||||
export let url: string
|
||||
|
||||
let video_info = {};
|
||||
let status = {};
|
||||
let statusBadge = {
|
||||
1: {"class": "badge bg-secondary", "text": "Downloading"},
|
||||
2: {"class": "badge bg-success", "text": "Completed"},
|
||||
3: {"class": "badge bg-error", "text": "Error"}
|
||||
};
|
||||
let download_path = "#";
|
||||
|
||||
async function startDownload() {
|
||||
// FIXME: Payload shoud be sent as JSON
|
||||
const res = await fetch(`${endpoint}/task`, {method: 'POST', body: new URLSearchParams({'url': url})});
|
||||
video_info = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
return video_info;
|
||||
} else {
|
||||
throw new Error(video_info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function getStatus() {
|
||||
const res = await fetch(`${endpoint}/task/${video_info.ID}`);
|
||||
status = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
if (status.Id) {
|
||||
download_path = `${endpoint}/data/${status.Id}`;
|
||||
}
|
||||
return status;
|
||||
} else {
|
||||
throw new Error(status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const interval = setInterval(() => { getStatus(); }, 1000);
|
||||
onMount(async () => {
|
||||
const res = await fetch(`${endpoint}/task`, {method: 'POST', body: new URLSearchParams({'url': url})})
|
||||
const videoInfo = await res.json()
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
|
|
62
frontend/src/Task.svelte.backup
Normal file
62
frontend/src/Task.svelte.backup
Normal file
|
@ -0,0 +1,62 @@
|
|||
<script>
|
||||
export let url;
|
||||
export let endpoint;
|
||||
|
||||
let video_info = {};
|
||||
let status = {};
|
||||
let statusBadge = {
|
||||
1: {"class": "badge bg-secondary", "text": "Downloading"},
|
||||
2: {"class": "badge bg-success", "text": "Completed"},
|
||||
3: {"class": "badge bg-error", "text": "Error"}
|
||||
};
|
||||
let download_path = "#";
|
||||
|
||||
async function startDownload() {
|
||||
// FIXME: Payload shoud be sent as JSON
|
||||
const res = await fetch(`${endpoint}/task`, {method: 'POST', body: new URLSearchParams({'url': url})});
|
||||
video_info = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
return video_info;
|
||||
} else {
|
||||
throw new Error(video_info);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async function getStatus() {
|
||||
const res = await fetch(`${endpoint}/task/${video_info.ID}`);
|
||||
status = await res.json();
|
||||
|
||||
if (res.ok) {
|
||||
if (status.ID) {
|
||||
download_path = `${endpoint}/data/${status.ID}`;
|
||||
}
|
||||
return status;
|
||||
} else {
|
||||
throw new Error(status);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const interval = setInterval(() => { getStatus(); }, 1000);
|
||||
|
||||
</script>
|
||||
|
||||
{#await startDownload()}
|
||||
<p>waiting...</p>
|
||||
{:then video_info}
|
||||
<a href={download_path} class="list-group-item list-group-item-action" aria-current="true">
|
||||
<div class="d-flex bd-highlight">
|
||||
<div class="pb-2 flex-grow-1 bd-highlight"><h5>{video_info.Title}</h5></div>
|
||||
<div class="pb-2 px-2 bd-highlight"><small>2 minutes ago</small></div>
|
||||
{#if status.Status}
|
||||
<div class="pb-2 px-2 bd-highlight"><span class={statusBadge[status.Status].class}>{statusBadge[status.Status].text}</span></div>
|
||||
{/if}
|
||||
</div>
|
||||
<p><small>{url}</small></p>
|
||||
<img alt="This is a thumbnail" src={video_info.Thumbnails[0].URL}/>
|
||||
</a>
|
||||
{:catch error}
|
||||
<p style="color: red">{error.message}</p>
|
||||
{/await}
|
29
tmux.bash
Executable file
29
tmux.bash
Executable file
|
@ -0,0 +1,29 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Set Session Name
|
||||
SESSION="yt-dls"
|
||||
SESSIONEXISTS=$(tmux list-sessions | grep $SESSION)
|
||||
|
||||
# Only create tmux session if it doesn't already exist
|
||||
if [ "$SESSIONEXISTS" = "" ]
|
||||
then
|
||||
# Start New Session with our name
|
||||
tmux new-session -d -s $SESSION
|
||||
|
||||
# Name first Pane and start zsh
|
||||
tmux rename-window -t 0 'Main'
|
||||
|
||||
# Create and setup pane for running the backend
|
||||
# tmux send-keys -t 'Main' 'bash' C-m 'clear' C-m 'cd backend && go build -o backend . && ./backend' C-m
|
||||
tmux send-keys -t 'Main' 'cd backend && go build -o backend . && ./backend' C-m
|
||||
|
||||
# Create and setup pane for running the backend
|
||||
tmux split-window -h 'cd frontend && npm run dev'
|
||||
|
||||
# Create an horizontal pane for terminal commands
|
||||
tmux split-window -vf -l 1
|
||||
tmux send-keys 'emacs backend/main.go &' Enter
|
||||
fi
|
||||
|
||||
# Attach Session, on the Main window
|
||||
tmux attach-session -t $SESSION:0
|
Loading…
Reference in a new issue