File manager mockup
This commit is contained in:
@@ -23,21 +23,21 @@ func (wc *WebController) serveFilePreview(w http.ResponseWriter, r *http.Request
|
||||
serveFilePreviewDemo(w) // Required for a-ads.com quality check
|
||||
return
|
||||
}
|
||||
|
||||
inf, err := wc.api.GetFileInfo(p.ByName("id")) // TODO: Error handling
|
||||
var api = pixelapi.New(wc.conf.APIURLInternal, "")
|
||||
inf, err := api.GetFileInfo(p.ByName("id")) // TODO: Error handling
|
||||
if err != nil {
|
||||
wc.serveNotFound(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
var fp = FilePreview{
|
||||
var fp = filePreview{
|
||||
APIURL: wc.conf.APIURLExternal,
|
||||
PixelAPI: wc.api,
|
||||
PixelAPI: api,
|
||||
}
|
||||
io.WriteString(w, fp.Run(inf))
|
||||
io.WriteString(w, fp.run(inf))
|
||||
}
|
||||
|
||||
type FilePreview struct {
|
||||
type filePreview struct {
|
||||
FileInfo *pixelapi.FileInfo
|
||||
FileURL string
|
||||
DownloadURL string
|
||||
@@ -46,7 +46,7 @@ type FilePreview struct {
|
||||
PixelAPI *pixelapi.PixelAPI
|
||||
}
|
||||
|
||||
func (f FilePreview) Run(inf *pixelapi.FileInfo) string {
|
||||
func (f filePreview) run(inf *pixelapi.FileInfo) string {
|
||||
f.FileInfo = inf
|
||||
f.FileURL = f.APIURL + "/file/" + f.FileInfo.ID
|
||||
f.DownloadURL = f.APIURL + "/file/" + f.FileInfo.ID + "/download"
|
||||
@@ -92,7 +92,7 @@ func (f FilePreview) Run(inf *pixelapi.FileInfo) string {
|
||||
return f.def()
|
||||
}
|
||||
|
||||
func (f FilePreview) image() string {
|
||||
func (f filePreview) image() string {
|
||||
return fmt.Sprintf(`<div class="image-container">
|
||||
<img id="displayImg" src="%s" class="pannable drop-shadow"/>
|
||||
</div>
|
||||
@@ -100,7 +100,7 @@ func (f FilePreview) image() string {
|
||||
f.FileURL)
|
||||
}
|
||||
|
||||
func (f FilePreview) audio() string {
|
||||
func (f filePreview) audio() string {
|
||||
return fmt.Sprintf(`<div class="image-container">
|
||||
<br/><br/>
|
||||
<img src="/res/img/mime/audio.png" alt="Audio"/>
|
||||
@@ -115,7 +115,7 @@ func (f FilePreview) audio() string {
|
||||
)
|
||||
}
|
||||
|
||||
func (f FilePreview) video() string {
|
||||
func (f filePreview) video() string {
|
||||
return fmt.Sprintf(`<div class="image-container">
|
||||
<video id="videoPlayer" autoplay="autoplay" controls="controls" class="center drop-shadow">
|
||||
<source src="%s"/>
|
||||
@@ -128,12 +128,12 @@ Your web browser does not support the HTML video tag.
|
||||
|
||||
}
|
||||
|
||||
func (f FilePreview) pdf() string {
|
||||
func (f filePreview) pdf() string {
|
||||
u, _ := url.Parse(f.FileURL)
|
||||
return f.frame("/res/misc/pdf-viewer/web/viewer.html?file=" + u.String())
|
||||
}
|
||||
|
||||
func (f FilePreview) text() string {
|
||||
func (f filePreview) text() string {
|
||||
htmlOut := `<div class="text-container">
|
||||
<pre class="pre-container %s" style="width: 100%%;">%s</pre>
|
||||
</div>`
|
||||
@@ -180,7 +180,7 @@ func (f FilePreview) text() string {
|
||||
return fmt.Sprintf(htmlOut, prettyPrint, result)
|
||||
}
|
||||
|
||||
func (f FilePreview) frame(url string) string {
|
||||
func (f filePreview) frame(url string) string {
|
||||
return fmt.Sprintf(`<iframe src="%s" class="image-container"
|
||||
seamless="seamless" frameborder="0" allowtransparency="true"
|
||||
</iframe>`,
|
||||
@@ -188,7 +188,7 @@ seamless="seamless" frameborder="0" allowtransparency="true"
|
||||
)
|
||||
}
|
||||
|
||||
func (f FilePreview) def() string {
|
||||
func (f filePreview) def() string {
|
||||
return fmt.Sprintf(
|
||||
`%s<br/>%s<br/><a href="%s"><img src="%s" class="image"></a>`,
|
||||
f.FileInfo.FileName,
|
||||
|
@@ -26,9 +26,10 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
||||
ids = append(ids, p.ByName("id"))
|
||||
}
|
||||
|
||||
var api = pixelapi.New(wc.conf.APIURLInternal, "")
|
||||
var finfo []*pixelapi.FileInfo
|
||||
for _, id := range ids {
|
||||
inf, err := wc.api.GetFileInfo(id)
|
||||
inf, err := api.GetFileInfo(id)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@@ -12,7 +12,8 @@ import (
|
||||
|
||||
// ServeListViewer controller for GET /l/:id
|
||||
func (wc *WebController) serveListViewer(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
|
||||
var list, err = wc.api.GetList(p.ByName("id"))
|
||||
var api = pixelapi.New(wc.conf.APIURLInternal, "")
|
||||
var list, err = api.GetList(p.ByName("id"))
|
||||
if err != nil {
|
||||
if (err.(pixelapi.Error)).ReqError {
|
||||
log.Error("API request error occurred: %s", (err.(pixelapi.Error)).Value)
|
||||
|
@@ -7,25 +7,26 @@ import (
|
||||
"github.com/google/uuid"
|
||||
|
||||
"fornaxian.com/pixeldrain-web/init/conf"
|
||||
"fornaxian.com/pixeldrain-web/pixelapi"
|
||||
"fornaxian.com/pixeldrain-web/webcontroller/templates"
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
// WebController controls how requests are handled and makes sure they have
|
||||
// proper context when running
|
||||
type WebController struct {
|
||||
conf *conf.PixelWebConfig
|
||||
api *pixelapi.PixelAPI // Shared instance, only used for unauthenticated requests
|
||||
templates *templates.TemplateManager
|
||||
staticResourceDir string
|
||||
}
|
||||
|
||||
// New initializes a new WebController by registering all the request handlers
|
||||
// and parsing all templates in the resource directory
|
||||
func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebController {
|
||||
var wc = &WebController{
|
||||
conf: conf,
|
||||
staticResourceDir: conf.StaticResourceDir,
|
||||
}
|
||||
wc.api = pixelapi.New(conf.APIURLInternal, "")
|
||||
wc.templates = templates.New(
|
||||
conf.TemplateDir,
|
||||
conf.APIURLExternal,
|
||||
@@ -36,22 +37,25 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
||||
// Serve static files
|
||||
r.ServeFiles(prefix+"/res/*filepath", http.Dir(wc.staticResourceDir+"/res"))
|
||||
|
||||
r.GET(prefix+"/" /* */, wc.serveTemplate("home", false))
|
||||
r.GET(prefix+"/favicon.ico" /* */, wc.serveFile("/favicon.ico"))
|
||||
r.GET(prefix+"/global.css" /* */, wc.globalCSSHandler)
|
||||
r.GET(prefix+"/api" /* */, wc.serveTemplate("apidoc", false))
|
||||
r.GET(prefix+"/history" /* */, wc.serveTemplate("history_cookies", false))
|
||||
r.GET(prefix+"/u/:id" /* */, wc.serveFileViewer)
|
||||
r.GET(prefix+"/u/:id/preview" /**/, wc.serveFilePreview)
|
||||
r.GET(prefix+"/l/:id" /* */, wc.serveListViewer)
|
||||
r.GET(prefix+"/t" /* */, wc.serveTemplate("paste", false))
|
||||
// General navigation
|
||||
r.GET(prefix+"/" /* */, wc.serveTemplate("home", false))
|
||||
r.GET(prefix+"/favicon.ico" /* */, wc.serveFile("/favicon.ico"))
|
||||
r.GET(prefix+"/global.css" /* */, wc.globalCSSHandler)
|
||||
r.GET(prefix+"/api" /* */, wc.serveTemplate("apidoc", false))
|
||||
r.GET(prefix+"/history" /* */, wc.serveTemplate("history_cookies", false))
|
||||
r.GET(prefix+"/u/:id" /* */, wc.serveFileViewer)
|
||||
r.GET(prefix+"/u/:id/preview" /* */, wc.serveFilePreview)
|
||||
r.GET(prefix+"/l/:id" /* */, wc.serveListViewer)
|
||||
r.GET(prefix+"/t" /* */, wc.serveTemplate("paste", false))
|
||||
|
||||
r.GET(prefix+"/register" /* */, wc.serveTemplate("register", false))
|
||||
r.GET(prefix+"/login" /* */, wc.serveTemplate("login", false))
|
||||
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout", true))
|
||||
r.POST(prefix+"/logout" /* */, wc.serveLogout)
|
||||
r.GET(prefix+"/user" /* */, wc.serveTemplate("user_home", true))
|
||||
r.GET(prefix+"/user/files" /* */, wc.serveTemplate("user_files", true))
|
||||
// User account pages
|
||||
r.GET(prefix+"/register" /* */, wc.serveTemplate("register", false))
|
||||
r.GET(prefix+"/login" /* */, wc.serveTemplate("login", false))
|
||||
r.GET(prefix+"/logout" /* */, wc.serveTemplate("logout", true))
|
||||
r.POST(prefix+"/logout" /* */, wc.serveLogout)
|
||||
r.GET(prefix+"/user" /* */, wc.serveTemplate("user_home", true))
|
||||
r.GET(prefix+"/user/files" /* */, wc.serveTemplate("user_files", true))
|
||||
r.GET(prefix+"/user/filemanager" /**/, wc.serveTemplate("file_manager", true))
|
||||
|
||||
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
||||
|
||||
|
Reference in New Issue
Block a user