api update
This commit is contained in:
@@ -15,11 +15,11 @@ func (p *PixelAPI) GetFile(id string) (io.ReadCloser, error) {
|
||||
type FileInfo struct {
|
||||
Success bool `json:"success"`
|
||||
ID string `json:"id"`
|
||||
FileName string `json:"file_name"`
|
||||
Name string `json:"name"`
|
||||
Size uint64 `json:"size"`
|
||||
Views int `json:"views"`
|
||||
DateUpload time.Time `json:"date_upload"`
|
||||
DateLastview time.Time `json:"date_last_view"`
|
||||
FileSize uint64 `json:"file_size"`
|
||||
Views uint `json:"views"`
|
||||
DateLastView time.Time `json:"date_last_view"`
|
||||
MimeType string `json:"mime_type"`
|
||||
MimeImage string `json:"mime_image"`
|
||||
ThumbnailHREF string `json:"thumbnail_href"`
|
||||
|
@@ -9,23 +9,22 @@ const (
|
||||
|
||||
// List information object from the pixeldrain API
|
||||
type List struct {
|
||||
Success bool `json:"success"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
DateCreated time.Time `json:"date_created"`
|
||||
FileCount int `json:"file_count"`
|
||||
Files []ListFile
|
||||
Success bool `json:"success"`
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
DateCreated time.Time `json:"date_created"`
|
||||
FileCount int `json:"file_count"`
|
||||
Files []ListFile `json:"files,omitempty"`
|
||||
}
|
||||
|
||||
// ListFile information object from the pixeldrain API
|
||||
type ListFile struct {
|
||||
ID string `json:"id"`
|
||||
DetailHREF string `json:"detail_href"`
|
||||
FileName string `json:"file_name"`
|
||||
Description string `json:"description"`
|
||||
DateCreated time.Time `json:"date_created"`
|
||||
DateLastView time.Time `json:"date_last_view"`
|
||||
ListDescription string `json:"list_description"`
|
||||
ID string `json:"id"`
|
||||
DetailHREF string `json:"detail_href"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
DateCreated time.Time `json:"date_created"`
|
||||
DateLastView time.Time `json:"date_last_view"`
|
||||
}
|
||||
|
||||
// GetList get a List from the pixeldrain API. Errors will be available through
|
||||
|
@@ -22,11 +22,11 @@ var DetailsWindow = {
|
||||
success: function(data){
|
||||
$("#info_file_details").html(
|
||||
"<table>"
|
||||
+ "<tr><td>Name<td><td>" + escapeHTML(data.file_name) + "</td></tr>"
|
||||
+ "<tr><td>Name<td><td>" + escapeHTML(data.name) + "</td></tr>"
|
||||
+ "<tr><td>Url<td><td><a href=\"/u/" + data.id + "\">/u/" + data.id + "</a></td></tr>"
|
||||
+ "<tr><td>Mime Type<td><td>" + escapeHTML(data.mime_type) + "</td></tr>"
|
||||
+ "<tr><td>Id<td><td>" + data.id + "</td></tr>"
|
||||
+ "<tr><td>Size<td><td class=\"bytecounter\">" + data.file_size + "</td></tr>"
|
||||
+ "<tr><td>Size<td><td class=\"bytecounter\">" + data.size + "</td></tr>"
|
||||
+ "<tr><td>Upload Date<td><td>" + data.date_upload + "</td></tr>"
|
||||
+ "<tr><td>Description<td><td>" + escapeHTML(file.description) + "</td></tr>"
|
||||
+ "</table>"
|
||||
@@ -36,10 +36,10 @@ var DetailsWindow = {
|
||||
} else {
|
||||
$("#info_file_details").html(
|
||||
"<table>"
|
||||
+ "<tr><td>Name<td><td>" + escapeHTML(file.file_name) + "</td></tr>"
|
||||
+ "<tr><td>Name<td><td>" + escapeHTML(file.name) + "</td></tr>"
|
||||
+ "<tr><td>Mime Type<td><td>" + escapeHTML(file.mime_type) + "</td></tr>"
|
||||
+ "<tr><td>Id<td><td>" + file.id + "</td></tr>"
|
||||
+ "<tr><td>Size<td><td class=\"bytecounter\">" + file.file_size + "</td></tr>"
|
||||
+ "<tr><td>Size<td><td class=\"bytecounter\">" + file.size + "</td></tr>"
|
||||
+ "<tr><td>Upload Date<td><td>" + file.date_upload + "</td></tr>"
|
||||
+ "</table>"
|
||||
);
|
||||
|
@@ -127,7 +127,7 @@ var ListNavigator = {
|
||||
|
||||
for (i = startPos; i <= endPos; i++){
|
||||
var thumb = "/api/file/" + this.data[i].id + "/thumbnail";
|
||||
var name = this.data[i].file_name;
|
||||
var name = this.data[i].name;
|
||||
|
||||
var itemHtml = escapeHTML(name) + "<br>"
|
||||
+ "<img src=\"" + thumb + "\" "
|
||||
@@ -144,8 +144,8 @@ var ListNavigator = {
|
||||
|
||||
$.each(data, function(i, item){
|
||||
var filename;
|
||||
if(item.file_name !== "null"){
|
||||
filename = item.file_name;
|
||||
if(item.name !== "null"){
|
||||
filename = item.name;
|
||||
}else{
|
||||
filename = "Removed File";
|
||||
}
|
||||
|
@@ -6,19 +6,19 @@ var Viewer = {
|
||||
isList: false,
|
||||
isFile: false,
|
||||
initialized: false,
|
||||
|
||||
|
||||
init: function(type, data){
|
||||
if(this.initialized){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// On small screens the toolbar takes too much space, so it collapses automatically
|
||||
if($("#filepreview").width() < 400 && Toolbar.visible){
|
||||
window.setTimeout(function(){
|
||||
Toolbar.toggle();
|
||||
}, 800);
|
||||
}
|
||||
|
||||
|
||||
if(type === "file"){
|
||||
this.isFile = true;
|
||||
this.currentFile = data.id;
|
||||
@@ -28,17 +28,17 @@ var Viewer = {
|
||||
this.listId = data.id;
|
||||
ListNavigator.init(data.data);
|
||||
}
|
||||
|
||||
|
||||
this.initialized = true;
|
||||
},
|
||||
setFile: function(file){
|
||||
this.currentFile = file.id;
|
||||
document.title = file.file_name + " ~ PixelDrain";
|
||||
|
||||
document.title = file.name + " ~ PixelDrain";
|
||||
|
||||
$.get("/u/" + file.id + "/preview", function(response){
|
||||
$("#filepreview").html(response);
|
||||
});
|
||||
|
||||
|
||||
DetailsWindow.setDetails(file);
|
||||
Toolbar.setViews(file.views);
|
||||
}
|
||||
@@ -51,4 +51,4 @@ function escapeHTML(str) {
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"');
|
||||
}
|
||||
}
|
||||
|
@@ -50,8 +50,8 @@ function historyAddItem(json) {
|
||||
|
||||
var uploadItem = '<a href="/u/'+ json.id +'" target="_blank" class="file_button">'
|
||||
+ '<img src="'+ apiEndpoint + json.thumbnail_href + '"'
|
||||
+ "alt=\"" + json.file_name + "\" />"
|
||||
+ '<span style="color: var(--highlight_color);">'+json.file_name+'</span>'
|
||||
+ "alt=\"" + json.name + "\" />"
|
||||
+ '<span style="color: var(--highlight_color);">'+json.name+'</span>'
|
||||
+ "<br/>"
|
||||
+ date.getFullYear() + "-"
|
||||
+ ("00" + (date.getMonth() + 1)).slice(-2) + "-"
|
||||
|
@@ -250,7 +250,7 @@ select{
|
||||
border: none;
|
||||
margin: 2px;
|
||||
background: linear-gradient(var(--input_color), var(--input_color_dark));
|
||||
padding: 6px 10px 6px 10px;
|
||||
padding: 6px 8px 6px 8px;
|
||||
box-shadow: 2px 2px 8px var(--shadow_color);
|
||||
font-weight: bold;
|
||||
font-size: 0.85em;
|
||||
|
@@ -50,8 +50,8 @@
|
||||
{{$files := .PixelAPI.UserFiles 0 20}}
|
||||
{{range $files.Files}}
|
||||
<a class="file_button" href="/u/{{.ID}}" target="_blank">
|
||||
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.FileName}}" />
|
||||
{{.FileName}}
|
||||
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.File}}" />
|
||||
{{.File}}
|
||||
</a>
|
||||
{{end}}
|
||||
</div>
|
||||
|
@@ -17,8 +17,8 @@
|
||||
{{$files := .PixelAPI.UserFiles 0 1000}}
|
||||
{{range $files.Files}}
|
||||
<a class="file_button" href="/u/{{.ID}}" target="_blank">
|
||||
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.FileName}}" />
|
||||
<span style="color: var(--highlight_color);">{{.FileName}}</span>
|
||||
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.Name}}" />
|
||||
<span style="color: var(--highlight_color);">{{.Name}}</span>
|
||||
<br/>
|
||||
{{.DateUpload.Format "2006-01-02 15:04:05"}}
|
||||
</a>
|
||||
|
@@ -15,8 +15,8 @@
|
||||
{{$files := .PixelAPI.UserFiles 0 18}}
|
||||
{{range $files.Files}}
|
||||
<a class="file_button" href="/u/{{.ID}}" target="_blank">
|
||||
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.FileName}}" />
|
||||
<span style="color: var(--highlight_color);">{{.FileName}}</span>
|
||||
<img src="{{$.APIEndpoint}}/file/{{.ID}}/thumbnail" alt="{{.Name}}" />
|
||||
<span style="color: var(--highlight_color);">{{.Name}}</span>
|
||||
<br/>
|
||||
{{.DateUpload.Format "2006-01-02 15:04:05"}}
|
||||
</a>
|
||||
|
@@ -144,10 +144,10 @@
|
||||
{
|
||||
"success": true,
|
||||
"id": "123abc",
|
||||
"file_name": "screenshot.png",
|
||||
"name": "screenshot.png",
|
||||
"date_upload": 1485894987, // Timestamp
|
||||
"date_last_view": 1485894987, // Timestamp
|
||||
"file_size": 5694837, // Bytes
|
||||
"size": 5694837, // Bytes
|
||||
"views" 1234, // Amount of unique file views
|
||||
"mime_type" "image/png",
|
||||
"description": "File description",
|
||||
|
@@ -117,10 +117,10 @@
|
||||
"file_info": {
|
||||
"success": true,
|
||||
"id": "Jf_u5TI9",
|
||||
"file_name": "11. Lenny Kravitz - Fly away.ogg",
|
||||
"name": "11. Lenny Kravitz - Fly away.ogg",
|
||||
"date_upload": "2018-07-04T22:24:48Z",
|
||||
"date_last_view": "2018-07-04T22:24:48Z",
|
||||
"file_size": 9757269,
|
||||
"size": 9757269,
|
||||
"views": 0,
|
||||
"mime_type": "application/ogg",
|
||||
"thumbnail_href": "/file/Jf_u5TI9/thumbnail"
|
||||
|
@@ -39,9 +39,11 @@
|
||||
<pre>HTTP 422: Unprocessable Entity
|
||||
{
|
||||
"success": false,
|
||||
"value": "file_not_found",
|
||||
"id": "Oh42No", // The file you tried to add with this ID does not exist
|
||||
"message": "File Oh42No was not found in the database."
|
||||
"value": "list_file_not_found",
|
||||
"message": "File Oh42No was not found in the database.",
|
||||
"extra": {
|
||||
"file_not_found": "0h42No" // The file you tried to add with this ID does not exist
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
<pre>HTTP 413: Payload too large
|
||||
@@ -124,7 +126,7 @@
|
||||
{
|
||||
"detail_href": "/file/_SqVWi/info",
|
||||
"id": "_SqVWi",
|
||||
"file_name": "01 Holy Wars... The Punishment Due.mp3",
|
||||
"name": "01 Holy Wars... The Punishment Due.mp3",
|
||||
"description": "",
|
||||
"date_created": 1513033304,
|
||||
"date_last_view": 1513033304
|
||||
@@ -132,7 +134,7 @@
|
||||
{
|
||||
"detail_href": "/file/RKwgZb/info",
|
||||
"id": "RKwgZb",
|
||||
"file_name": "02 Hangar 18.mp3",
|
||||
"name": "02 Hangar 18.mp3",
|
||||
"description": "",
|
||||
"date_created": 1513033304,
|
||||
"date_last_view": 1513033304
|
||||
@@ -140,7 +142,7 @@
|
||||
{
|
||||
"detail_href": "/file/DRaL_e/info",
|
||||
"id": "DRaL_e",
|
||||
"file_name": "03 Take No Prisoners.mp3",
|
||||
"name": "03 Take No Prisoners.mp3",
|
||||
"description": "",
|
||||
"date_created": 1513033304,
|
||||
"date_last_view": 1513033304
|
||||
|
@@ -78,7 +78,7 @@ func (f filePreview) run(inf *pixelapi.FileInfo) string {
|
||||
return f.pdf()
|
||||
case
|
||||
"application/octet-stream": // Fallback for when mime type not recognized
|
||||
switch filepath.Ext(f.FileInfo.FileName) {
|
||||
switch filepath.Ext(f.FileInfo.Name) {
|
||||
case
|
||||
".mp3":
|
||||
return f.audio()
|
||||
@@ -110,7 +110,7 @@ func (f filePreview) audio() string {
|
||||
</audio>
|
||||
</div>
|
||||
<script src="/res/viewer-scripts/audio.js"></script>`,
|
||||
f.FileInfo.FileName,
|
||||
f.FileInfo.Name,
|
||||
f.FileURL,
|
||||
)
|
||||
}
|
||||
@@ -138,7 +138,7 @@ func (f filePreview) text() string {
|
||||
<pre class="pre-container %s" style="width: 100%%;">%s</pre>
|
||||
</div>`
|
||||
|
||||
if f.FileInfo.FileSize > 1e6 { // Prevent out of memory errors
|
||||
if f.FileInfo.Size > 1e6 { // Prevent out of memory errors
|
||||
return fmt.Sprintf(htmlOut, "",
|
||||
"File is too large to view online.\nPlease download and view it locally.",
|
||||
)
|
||||
@@ -191,7 +191,7 @@ seamless="seamless" frameborder="0" allowtransparency="true"
|
||||
func (f filePreview) def() string {
|
||||
return fmt.Sprintf(
|
||||
`%s<br/>%s<br/><a href="%s"><img src="%s" class="image"></a>`,
|
||||
f.FileInfo.FileName,
|
||||
f.FileInfo.Name,
|
||||
f.FileInfo.MimeType,
|
||||
f.DownloadURL,
|
||||
f.APIURL+f.FileInfo.ThumbnailHREF,
|
||||
|
@@ -61,7 +61,7 @@ func (wc *WebController) serveFileViewer(w http.ResponseWriter, r *http.Request,
|
||||
})
|
||||
} else {
|
||||
err = wc.templates.Get().ExecuteTemplate(w, "file_viewer", map[string]interface{}{
|
||||
"Title": fmt.Sprintf("%s ~ Pixeldrain file", finfo[0].FileName),
|
||||
"Title": fmt.Sprintf("%s ~ Pixeldrain file", finfo[0].Name),
|
||||
"APIResponse": finfo[0],
|
||||
"Type": "file",
|
||||
"OGData": ogData.FromFile(*finfo[0]),
|
||||
@@ -80,10 +80,10 @@ func (wc *WebController) serveFileViewerDemo(w http.ResponseWriter) {
|
||||
wc.templates.Get().ExecuteTemplate(w, "file_viewer", map[string]interface{}{
|
||||
"APIResponse": map[string]interface{}{
|
||||
"id": "demo",
|
||||
"file_name": "Demo file",
|
||||
"name": "Demo file",
|
||||
"date_upload": "2017-01-01 12:34:56",
|
||||
"date_lastview": "2017-01-01 12:34:56",
|
||||
"file_size": 123456789,
|
||||
"size": 123456789,
|
||||
"views": 1,
|
||||
"mime_type": "text/demo",
|
||||
"description": "A file to demonstrate the viewer page",
|
||||
|
@@ -18,10 +18,10 @@ type OGData struct {
|
||||
// FromFile populates the OGData object from FileInfo. It returns itself for
|
||||
// compactness.
|
||||
func (d *OGData) FromFile(f pixelapi.FileInfo) *OGData {
|
||||
d.Title = f.FileName
|
||||
d.Title = f.Name
|
||||
d.Type = "website"
|
||||
d.SiteName = "Pixeldrain"
|
||||
d.Description = "View " + f.FileName + " on Pixeldrain"
|
||||
d.Description = "View " + f.Name + " on Pixeldrain"
|
||||
d.URL = "/u/" + f.ID
|
||||
d.Image = "/api/file/" + f.ID + "/thumbnail"
|
||||
return d
|
||||
|
@@ -36,28 +36,30 @@ func New(r *httprouter.Router, prefix string, conf *conf.PixelWebConfig) *WebCon
|
||||
)
|
||||
wc.templates.ParseTemplates(false)
|
||||
|
||||
var p = prefix
|
||||
|
||||
// Serve static files
|
||||
r.ServeFiles(prefix+"/res/*filepath", http.Dir(wc.staticResourceDir+"/res"))
|
||||
r.ServeFiles(p+"/res/*filepath", http.Dir(wc.staticResourceDir+"/res"))
|
||||
|
||||
// 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(p+"/" /* */, wc.serveTemplate("home", false))
|
||||
r.GET(p+"/favicon.ico" /* */, wc.serveFile("/favicon.ico"))
|
||||
r.GET(p+"/global.css" /* */, wc.globalCSSHandler)
|
||||
r.GET(p+"/api" /* */, wc.serveTemplate("apidoc", false))
|
||||
r.GET(p+"/history" /* */, wc.serveTemplate("history_cookies", false))
|
||||
r.GET(p+"/u/:id" /* */, wc.serveFileViewer)
|
||||
r.GET(p+"/u/:id/preview" /* */, wc.serveFilePreview)
|
||||
r.GET(p+"/l/:id" /* */, wc.serveListViewer)
|
||||
r.GET(p+"/t" /* */, wc.serveTemplate("paste", false))
|
||||
|
||||
// User account pages
|
||||
r.GET(prefix+"/register" /* */, wc.serveRegister)
|
||||
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.GET(p+"/register" /* */, wc.serveRegister)
|
||||
r.GET(p+"/login" /* */, wc.serveTemplate("login", false))
|
||||
r.GET(p+"/logout" /* */, wc.serveTemplate("logout", true))
|
||||
r.POST(p+"/logout" /* */, wc.serveLogout)
|
||||
r.GET(p+"/user" /* */, wc.serveTemplate("user_home", true))
|
||||
r.GET(p+"/user/files" /* */, wc.serveTemplate("user_files", true))
|
||||
r.GET(p+"/user/filemanager" /**/, wc.serveTemplate("file_manager", true))
|
||||
|
||||
r.NotFound = http.HandlerFunc(wc.serveNotFound)
|
||||
|
||||
@@ -97,6 +99,7 @@ func (wc *WebController) serveFile(path string) httprouter.Handle {
|
||||
|
||||
func (wc *WebController) serveNotFound(w http.ResponseWriter, r *http.Request) {
|
||||
log.Debug("Not Found: %s", r.URL)
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
wc.templates.Get().ExecuteTemplate(w, "404", wc.newTemplateData(w, r))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user