feat: Make upload path selectable (#39)
This works for me, but for a more public site, I think I'll also add a boolean attribute named "upload_allowed" and "writable" to Config.Library.. Something to allow you to configure which directories can receive new uploads, and which directories we consider writable for other purposes (like editing meta data in yml, creating new thumbnails, ...) Co-authored-by: Heinrich Langos <gumbo2000@noreply@mills.io> Reviewed-on: https://git.mills.io/prologic/tube/pulls/39 Co-authored-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io> Co-committed-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
This commit is contained in:
parent
7a4ef5b6df
commit
0a793f7d3f
3 changed files with 13 additions and 9 deletions
15
app/app.go
15
app/app.go
|
@ -236,15 +236,12 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
title := r.FormValue("video_title")
|
title := r.FormValue("video_title")
|
||||||
description := r.FormValue("video_description")
|
description := r.FormValue("video_description")
|
||||||
|
if _, exists := a.Library.Paths[r.FormValue("target_library_path")]; !exists {
|
||||||
// TODO: Make collection user selectable from drop-down in Form
|
err := fmt.Errorf("uploading to invalid library path: %s", r.FormValue("target_library_path"))
|
||||||
// XXX: Assume we can put uploaded videos into the first collection (sorted) we find
|
log.Error(err)
|
||||||
keys := make([]string, 0, len(a.Library.Paths))
|
return
|
||||||
for k := range a.Library.Paths {
|
|
||||||
keys = append(keys, k)
|
|
||||||
}
|
}
|
||||||
sort.Strings(keys)
|
targetLibraryPath := r.FormValue("target_library_path")
|
||||||
collection := keys[0]
|
|
||||||
|
|
||||||
uf, err := ioutil.TempFile(
|
uf, err := ioutil.TempFile(
|
||||||
a.Config.Server.UploadPath,
|
a.Config.Server.UploadPath,
|
||||||
|
@ -278,7 +275,7 @@ func (a *App) uploadHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vf := filepath.Join(
|
vf := filepath.Join(
|
||||||
a.Library.Paths[collection].Path,
|
a.Library.Paths[targetLibraryPath].Path,
|
||||||
fmt.Sprintf("%s.mp4", shortuuid.New()),
|
fmt.Sprintf("%s.mp4", shortuuid.New()),
|
||||||
)
|
)
|
||||||
thumbFn1 := fmt.Sprintf("%s.jpg", strings.TrimSuffix(tf.Name(), filepath.Ext(tf.Name())))
|
thumbFn1 := fmt.Sprintf("%s.jpg", strings.TrimSuffix(tf.Name(), filepath.Ext(tf.Name())))
|
||||||
|
|
|
@ -13,6 +13,7 @@ let file = null
|
||||||
|
|
||||||
const uploadForm = document.getElementById('upload-form')
|
const uploadForm = document.getElementById('upload-form')
|
||||||
const videoInput = document.getElementById('video-input')
|
const videoInput = document.getElementById('video-input')
|
||||||
|
const targetLibraryPath = document.getElementById('target-library-path')
|
||||||
const videoTitle = document.getElementById('video-title')
|
const videoTitle = document.getElementById('video-title')
|
||||||
const videoDescription = document.getElementById('video-description')
|
const videoDescription = document.getElementById('video-description')
|
||||||
const uploadMessageLabel = document.getElementById('upload-message')
|
const uploadMessageLabel = document.getElementById('upload-message')
|
||||||
|
@ -164,6 +165,7 @@ const startUploading = () => {
|
||||||
|
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('video_file', file)
|
formData.append('video_file', file)
|
||||||
|
formData.append('target_library_path', targetLibraryPath.value)
|
||||||
formData.append('video_title', videoTitle.value)
|
formData.append('video_title', videoTitle.value)
|
||||||
formData.append('video_description', videoDescription.value)
|
formData.append('video_description', videoDescription.value)
|
||||||
const xhr = new XMLHttpRequest()
|
const xhr = new XMLHttpRequest()
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
<span>Click to browse or drop file here</span>
|
<span>Click to browse or drop file here</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="upload-details">
|
<div class="upload-details">
|
||||||
|
<select id="target-library-path" name="target-library-path">
|
||||||
|
{{range $index, $item :=.Config.Library}}
|
||||||
|
<option value="{{$item.Path}}">{{$item.Path}}</option>
|
||||||
|
{{end}}
|
||||||
|
</select>
|
||||||
<input id="video-title" type="text" placeholder="Optional title" />
|
<input id="video-title" type="text" placeholder="Optional title" />
|
||||||
<textarea id="video-description" rows="2" placeholder="Optional description"></textarea>
|
<textarea id="video-description" rows="2" placeholder="Optional description"></textarea>
|
||||||
<div id="upload-file" class="upload-file">
|
<div id="upload-file" class="upload-file">
|
||||||
|
|
Loading…
Reference in a new issue