From 84c008bc27510c63fb22d14c8559e05e12953418 Mon Sep 17 00:00:00 2001 From: FChannel <> Date: Fri, 4 Jun 2021 21:44:43 -0700 Subject: added exif removal from jpeg, png images --- README.md | 4 +++- main.go | 62 +++++++++++++++++++++++++++++---------------------------- outboxPost.go | 15 +++++++++++++- static/faq.html | 2 +- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 44d3c3a..2f6740d 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Any contributions or suggestions are appreciated. Best way to give immediate fee ## Minimum Server Requirements -- Go v1.11+ +- Go v1.16+ - PostgreSQL @@ -28,6 +28,8 @@ Any contributions or suggestions are appreciated. Best way to give immediate fee - ImageMagick +- exiv2 + ## Server Installation Instructions - Ensure you have golang installed at a correct `GOPATH` diff --git a/main.go b/main.go index 604d3f2..ab619ab 100644 --- a/main.go +++ b/main.go @@ -27,7 +27,7 @@ var Domain = TP + "" + Instance var authReq = []string{"captcha","email","passphrase"} -var supportedFiles = []string{"image/gif","image/jpeg","image/png","image/svg+xml","image/svg","image/webp","image/avif","image/apng","video/mp4","video/ogg","video/webm","audio/mpeg","audio/ogg","audio/wav", "audio/wave", "audio/x-wav"} +var supportedFiles = []string{"image/gif","image/jpeg","image/png", "image/webp", "image/apng","video/mp4","video/ogg","video/webm","audio/mpeg","audio/ogg","audio/wav", "audio/wave", "audio/x-wav"} var SiteEmail = GetConfigValue("emailaddress") //contact@fchan.xyz var SiteEmailPassword = GetConfigValue("emailpass") @@ -1374,7 +1374,7 @@ func CreatePreviewObject(obj ObjectBase) *NestedObjectBase { objFile := re.FindString(obj.Href) - cmd := exec.Command("convert", "." + objFile ,"-resize", "250x250>", "." + href) + cmd := exec.Command("convert", "." + objFile ,"-resize", "250x250>", "-strip","." + href) err := cmd.Run() @@ -1809,31 +1809,33 @@ func MakeActivityRequest(db *sql.DB, activity Activity) { actor := FingerActor(e) - _, instance := GetActorInstance(actor.Id) - - if actor.Inbox != "" { - req, err := http.NewRequest("POST", actor.Inbox, bytes.NewBuffer(j)) - - date := time.Now().UTC().Format(time.RFC1123) - path := strings.Replace(actor.Inbox, instance, "", 1) - - re := regexp.MustCompile("https?://(www.)?") - path = re.ReplaceAllString(path, "") - - sig := fmt.Sprintf("(request-target): %s %s\\nhost: %s\\ndate: %s", "post", path, Instance, date) - encSig := ActivitySign(db, *activity.Actor, sig) - - req.Header.Set("Content-Type", activitystreams) - req.Header.Set("Date", date) - req.Header.Set("Signature", encSig) - req.Header.Set("Host", Instance) - req.Host = Instance - - CheckError(err, "error with sending activity req to") - - _, err = http.DefaultClient.Do(req) - - CheckError(err, "error with sending activity resp to") + if actor.Id != "" { + _, instance := GetActorInstance(actor.Id) + + if actor.Inbox != "" { + req, err := http.NewRequest("POST", actor.Inbox, bytes.NewBuffer(j)) + + date := time.Now().UTC().Format(time.RFC1123) + path := strings.Replace(actor.Inbox, instance, "", 1) + + re := regexp.MustCompile("https?://(www.)?") + path = re.ReplaceAllString(path, "") + + sig := fmt.Sprintf("(request-target): %s %s\\nhost: %s\\ndate: %s", "post", path, Instance, date) + encSig := ActivitySign(db, *activity.Actor, sig) + + req.Header.Set("Content-Type", activitystreams) + req.Header.Set("Date", date) + req.Header.Set("Signature", encSig) + req.Header.Set("Host", Instance) + req.Host = Instance + + CheckError(err, "error with sending activity req to") + + _, err = http.DefaultClient.Do(req) + + CheckError(err, "error with sending activity resp to") + } } } } @@ -2056,7 +2058,7 @@ func ResizeAttachmentToPreview(db *sql.DB) { objFile := re.FindString(href) if(id != "") { - cmd := exec.Command("convert", "." + objFile ,"-resize", "250x250>", "." + nHref) + cmd := exec.Command("convert", "." + objFile ,"-resize", "250x250>", "-strip", "." + nHref) err := cmd.Run() @@ -2245,7 +2247,7 @@ func FingerActor(path string) Actor{ var nActor Actor - if r.StatusCode == 200 { + if r != nil && r.StatusCode == 200 { defer r.Body.Close() body, _ := ioutil.ReadAll(r.Body) @@ -2271,7 +2273,7 @@ func FingerRequest(actor string, instance string) (*http.Response){ var finger Webfinger if err != nil { - CheckError(err, "could not get actor from finger resp with id " + acct) + return resp } if resp.StatusCode == 200 { diff --git a/outboxPost.go b/outboxPost.go index 5729b2d..ab8c451 100644 --- a/outboxPost.go +++ b/outboxPost.go @@ -10,6 +10,7 @@ import "io/ioutil" import "os" import "regexp" import "strings" +import "os/exec" func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { @@ -31,7 +32,7 @@ func ParseOutboxRequest(w http.ResponseWriter, r *http.Request, db *sql.DB) { } contentType, _ := GetFileContentType(f) - + if(!SupportedMIMEType(contentType)) { w.WriteHeader(http.StatusNotAcceptable) w.Write([]byte("file type not supported")) @@ -361,6 +362,18 @@ func ObjectFromForm(r *http.Request, db *sql.DB, obj ObjectBase) ObjectBase { tempFile.Write(fileBytes) + re := regexp.MustCompile(`image/(jpe?g|png|webp)`) + if re.MatchString(obj.Attachment[0].MediaType) { + fileLoc := strings.ReplaceAll(obj.Attachment[0].Href, Domain, "") + + cmd := exec.Command("exiv2", "rm", "." + fileLoc) + + err := cmd.Run() + + CheckError(err, "error with removing exif data from image") + + } + obj.Preview = CreatePreviewObject(obj.Attachment[0]) } diff --git a/static/faq.html b/static/faq.html index 66c053d..4398466 100644 --- a/static/faq.html +++ b/static/faq.html @@ -20,7 +20,7 @@
click on "No." next to a post to view its thread.
max file size is 7MB. the supported file types are "image/gif","image/jpeg","image/png","image/svg+xml","image/webp","image/avif","image/apng","video/mp4","video/ogg","video/webm","audio/mpeg","audio/ogg","audio/wav", "audio/wave", "audio/x-wav". these were choosen based on browser support for embeding.
+max file size is 7MB. the supported file types are "image/gif","image/jpeg","image/png","image/webp","image/apng","video/mp4","video/ogg","video/webm","audio/mpeg","audio/ogg","audio/wav","audio/wave","audio/x-wav". these were choosen based on browser support for embeding.
a version of the client with no javascript will be made eventually. current version requires it, because of basic functionality needed. no libraries or frameworks for javascript is used besides ECMAScript, just basic selection of DOM elements and modifying their styling. maybe someone would be willing to make a client that uses no javascript.
-- cgit v1.2.3