parse new video in new go function

validate extension on server to allow only videos
This commit is contained in:
lukas 2021-09-24 22:12:42 +02:00
parent 156aaa7a71
commit fd5542c528
3 changed files with 16 additions and 9 deletions

View File

@ -7,6 +7,7 @@ import (
"openmediacenter/apiGo/database" "openmediacenter/apiGo/database"
"openmediacenter/apiGo/videoparser" "openmediacenter/apiGo/videoparser"
"os" "os"
"path/filepath"
) )
func addUploadHandler() { func addUploadHandler() {
@ -21,8 +22,12 @@ func addUploadHandler() {
mr, err := req.MultipartReader() mr, err := req.MultipartReader()
if err != nil { if err != nil {
ctx.Errorf("incorrect request!")
return return
} }
videoparser.InitDeps(&mSettings)
//length := req.ContentLength //length := req.ContentLength
for { for {
part, err := mr.NextPart() part, err := mr.NextPart()
@ -30,9 +35,11 @@ func addUploadHandler() {
break break
} }
//var read int64 // todo allow more video formats than mp4
//var p float32 // only allow valid extensions
// todo check where we want to place this file if filepath.Ext(part.FileName()) != ".mp4" {
continue
}
vidpath := PathPrefix + mSettings.VideoPath + part.FileName() vidpath := PathPrefix + mSettings.VideoPath + part.FileName()
dst, err := os.OpenFile(vidpath, os.O_WRONLY|os.O_CREATE, 0644) dst, err := os.OpenFile(vidpath, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil { if err != nil {
@ -54,8 +61,7 @@ func addUploadHandler() {
if err == io.EOF { if err == io.EOF {
fmt.Printf("Finished uploading file %s\n", part.FileName()) fmt.Printf("Finished uploading file %s\n", part.FileName())
videoparser.InitDeps(&mSettings) go videoparser.ProcessVideo(part.FileName())
videoparser.ProcessVideo(part.FileName())
break break
} }
} }

View File

@ -13,7 +13,7 @@ server {
try_files $uri /index.html; try_files $uri /index.html;
} }
location ~* ^/(api/|token) { location ~* ^/(api) {
client_max_body_size 10G; client_max_body_size 10G;
proxy_pass http://127.0.0.1:8081; proxy_pass http://127.0.0.1:8081;
} }

View File

@ -10,8 +10,8 @@ export const DropZone = (): JSX.Element => {
const theme = GlobalInfos.getThemeStyle(); const theme = GlobalInfos.getThemeStyle();
const uploadFile = (f: FileList): void => { const uploadFile = (f: FileList): void => {
let xhr = new XMLHttpRequest(); // create XMLHttpRequest const xhr = new XMLHttpRequest(); // create XMLHttpRequest
let data = new FormData(); // create formData object const data = new FormData(); // create formData object
for (let i = 0; i < f.length; i++) { for (let i = 0; i < f.length; i++) {
const file = f.item(i); const file = f.item(i);
@ -22,6 +22,8 @@ export const DropZone = (): JSX.Element => {
xhr.onload = function (): void { xhr.onload = function (): void {
console.log(this.responseText); // whatever the server returns console.log(this.responseText); // whatever the server returns
setpercent(0);
}; };
xhr.upload.onprogress = function (e): void { xhr.upload.onprogress = function (e): void {
@ -70,7 +72,6 @@ export const DropZone = (): JSX.Element => {
input.multiple = true; input.multiple = true;
input.onchange = function (): void { input.onchange = function (): void {
if (input.files) { if (input.files) {
console.log(input.files);
uploadFile(input.files); uploadFile(input.files);
} }
}; };