Encode tiffs too.

Update file extension lists.
Update mod floater.
This commit is contained in:
Azareal 2019-10-30 13:52:04 +10:00
parent 9e8b95b1be
commit 01d956f9d1
6 changed files with 30 additions and 19 deletions

View File

@ -57,7 +57,7 @@ type StringList []string
// TODO: Let admins manage this from the Control Panel
// apng is commented out for now, as we have no way of re-encoding it into a smaller file
var AllowedFileExts = StringList{
"png", "jpg", "jpeg", "svg", "bmp", "gif", "tif", "webp", /*"apng",*/ // images
"png", "jpg", "jpeg","jfif", "svg", "bmp", "gif", "tiff","tif", "webp", /*"apng",*/ // images
"txt", "xml", "json", "yaml", "toml", "ini", "md", "html", "rtf", "js", "py", "rb", "css", "scss", "less", "eqcss", "pcss", "java", "ts", "cs", "c", "cc", "cpp", "cxx", "C", "c++", "h", "hh", "hpp", "hxx", "h++", "rs", "rlib", "htaccess", "gitignore", /*"go","php",*/ // text
@ -66,7 +66,7 @@ var AllowedFileExts = StringList{
"otf", "woff2", "woff", "ttf", "eot", // fonts
}
var ImageFileExts = StringList{
"png", "jpg", "jpeg","jfif", "svg", "bmp", "gif", "tif", "webp", /* "apng",*/
"png", "jpg", "jpeg","jfif", "svg", "bmp", "gif", "tiff","tif", "webp", /* "apng",*/
}
var ArchiveFileExts = StringList{
"bz2", "zip", "gz", "7z", "tar", "cab",

View File

@ -8,7 +8,9 @@ import (
"os"
"strconv"
"github.com/Azareal/Gosora/query_gen"
"golang.org/x/image/tiff"
qgen "github.com/Azareal/Gosora/query_gen"
"github.com/pkg/errors"
)
@ -47,7 +49,7 @@ func ThumbTask(thumbChan chan bool) {
/*if user.RawAvatar == ".gif" {
return nil
}*/
if user.RawAvatar != ".png" && user.RawAvatar != ".jpg" && user.RawAvatar != ".jpeg" && user.RawAvatar != ".jfif" && user.RawAvatar != ".gif" {
if user.RawAvatar != ".png" && user.RawAvatar != ".jpg" && user.RawAvatar != ".jpeg" && user.RawAvatar != ".jfif" && user.RawAvatar != ".gif" && user.RawAvatar != "tiff" && user.RawAvatar != "tif" {
return nil
}
@ -68,11 +70,11 @@ func ThumbTask(thumbChan chan bool) {
}
/*
err := acc.Select("attach_image_queue").Columns("attachID").Limit("0,5").EachInt(func(attachID int) error {
return nil
err := acc.Select("attach_image_queue").Columns("attachID").Limit("0,5").EachInt(func(attachID int) error {
return nil
_, err = acc.Delete("attach_image_queue").Where("attachID = ?").Run(uid)
}
_, err = acc.Delete("attach_image_queue").Where("attachID = ?").Run(uid)
}
*/
if err = acc.FirstError(); err != nil {
LogError(err)
@ -125,10 +127,13 @@ func precodeImage(format string, inPath string, tmpPath string) error {
defer outFile.Close()
// TODO: Make sure animated gifs work after being encoded
if format == "gif" {
switch format {
case "gif":
return gif.Encode(outFile, img, nil)
} else if format == "png" {
case "png":
return png.Encode(outFile, img)
case "tiff", "tif":
return tiff.Encode(outFile, img, nil)
}
return jpeg.Encode(outFile, img, nil)
}

View File

@ -226,7 +226,7 @@ func (s *DefaultTopicStore) Create(fid int, topicName string, content string, ui
}
// ? - What is this? Do we need it? Should it be in the main store interface?
func (s *DefaultTopicStore) AddLastTopic(item *Topic, fid int) error {
func (s *DefaultTopicStore) AddLastTopic(t *Topic, fid int) error {
// Coming Soon...
return nil
}

View File

@ -1,3 +1,6 @@
// TODO: Push ImageFileExts to the client from the server in some sort of gen.js?
var imageExts = ["png", "jpg", "jpeg","jfif", "svg", "bmp", "gif", "tiff","tif", "webp"];
(() => {
addInitHook("almost_end_init", () => {
function copyToClipboard(str) {
@ -49,7 +52,7 @@
let ext = getExt(filename);
// TODO: Push ImageFileExts to the client from the server in some sort of gen.js?
let isImage = ["png", "jpg", "jpeg", "svg", "bmp", "gif", "tif", "webp"].includes(ext);
let isImage = imageExts.includes(ext);
if(isImage) {
let reader = new FileReader();
reader.onload = f;
@ -79,7 +82,7 @@
let fileItem = document.createElement("div");
let ext = getExt(filename);
// TODO: Push ImageFileExts to the client from the server in some sort of gen.js?
let isImage = ["png", "jpg", "jpeg", "svg", "bmp", "gif", "tif", "webp"].includes(ext);
let isImage = imageExts.includes(ext);
let c = "";
if(isImage) c = " attach_image_holder"
fileItem.className = "attach_item attach_item_item" + c;
@ -115,7 +118,7 @@
let ext = getExt(filename);
// TODO: Push ImageFileExts to the client from the server in some sort of gen.js?
let isImage = ["png", "jpg", "jpeg", "svg", "bmp", "gif", "tif", "webp"].includes(ext);
let isImage = imageExts.includes(ext);
fileItem.innerText = "." + ext;
fileItem.className = "formbutton uploadItem";
// TODO: Check if this is actually an image
@ -249,7 +252,7 @@
event.preventDefault();
let selectNode = this.form.querySelector(".mod_floater_options");
let optionNode = selectNode.options[selectNode.selectedIndex];
let action = optionNode.getAttribute("val");
let action = optionNode.getAttribute("value");
// Handle these specially
switch(action) {

View File

@ -19,6 +19,7 @@ import (
"image/gif"
"image/jpeg"
"image/png"
"golang.org/x/image/tiff"
c "github.com/Azareal/Gosora/common"
"github.com/Azareal/Gosora/common/counters"
@ -494,7 +495,7 @@ func uploadFilesWithHash(w http.ResponseWriter, r *http.Request, user c.User, di
}
defer inFile.Close()
if ext != "jpg" && ext != "jpeg" && ext != "png" && ext != "gif" {
if ext != "jpg" && ext != "jpeg" && ext != "png" && ext != "gif" && ext != "tiff" && ext != "tif" {
outFile, err := os.Create(dir + filename)
if err != nil {
return nil, c.LocalError("Upload failed [File Creation Failed]", w, r, user)
@ -522,6 +523,8 @@ func uploadFilesWithHash(w http.ResponseWriter, r *http.Request, user c.User, di
err = gif.Encode(outFile, img, nil)
case "png":
err = png.Encode(outFile, img)
case "tiff","tif":
err = tiff.Encode(outFile,img,nil)
default:
err = jpeg.Encode(outFile, img, nil)
}

View File

@ -6,9 +6,9 @@
</div>
<div class="mod_floater_body">
<select class="mod_floater_options">
<option val="delete">{{lang "topic_list.moderate_delete"}}</option>
<option val="lock">{{lang "topic_list.moderate_lock"}}</option>
<option val="move">{{lang "topic_list.moderate_move"}}</option>
<option value="delete">{{lang "topic_list.moderate_delete"}}</option>
<option value="lock">{{lang "topic_list.moderate_lock"}}</option>
<option value="move">{{lang "topic_list.moderate_move"}}</option>
</select>
<button class="mod_floater_submit">{{lang "topic_list.moderate_run"}}</button>
</div>