diff --git a/handlers/embed.go b/handlers/embed.go
index 99b8ab1..1223705 100644
--- a/handlers/embed.go
+++ b/handlers/embed.go
@@ -3,6 +3,7 @@ package handlers
import (
"instafix/utils"
"instafix/views"
+ "instafix/views/model"
"net/url"
"strconv"
"strings"
@@ -30,7 +31,7 @@ func mediaidToCode(mediaID int) string {
func Embed() fiber.Handler {
return func(c *fiber.Ctx) error {
c.Set("Content-Type", "text/html; charset=utf-8")
- viewsData := &views.ViewsData{}
+ viewsData := &model.ViewsData{}
viewsBuf := bytebufferpool.Get()
defer bytebufferpool.Put(viewsBuf)
diff --git a/handlers/oembed.go b/handlers/oembed.go
index a705664..dedc7a8 100644
--- a/handlers/oembed.go
+++ b/handlers/oembed.go
@@ -2,6 +2,7 @@ package handlers
import (
"instafix/views"
+ "instafix/views/model"
"github.com/PurpleSec/escape"
"github.com/gofiber/fiber/v2"
@@ -20,7 +21,7 @@ func OEmbed() fiber.Handler {
defer bytebufferpool.Put(viewsBuf)
// Totally safe 100% valid template 👍
- OEmbedData := &views.OEmbedData{
+ OEmbedData := &model.OEmbedData{
Text: escape.JSON(headingText),
URL: headingURL,
}
diff --git a/views/embed.jade b/views/embed.jade
index 9dec8c1..0260478 100644
--- a/views/embed.jade
+++ b/views/embed.jade
@@ -1,4 +1,6 @@
-:go:func Embed(v *ViewsData)
+:go:func Embed(v *model.ViewsData)
+
+:go:import "instafix/views/model"
mixin for(golang)
#cmd Precompile jade templates to #{golang} code.
diff --git a/views/embed.jade.go b/views/embed.jade.go
index 5ddbb21..988fe9f 100644
--- a/views/embed.jade.go
+++ b/views/embed.jade.go
@@ -3,6 +3,8 @@
package views
import (
+ "instafix/views/model"
+
pool "github.com/valyala/bytebufferpool"
)
@@ -31,32 +33,32 @@ const (
embed__26 = `" type="application/json+oembed" title="`
)
-func Embed(v *ViewsData, buffer *pool.ByteBuffer) {
+func Embed(v *model.ViewsData, buffer *pool.ByteBuffer) {
buffer.WriteString(embed__0)
if v.Card != "" {
buffer.WriteString(embed__7)
- WriteAll(v.Card, true, buffer)
+ WriteEscString(v.Card, buffer)
buffer.WriteString(embed__3)
}
if v.Title != "" {
buffer.WriteString(embed__9)
- WriteAll(v.Title, true, buffer)
+ WriteEscString(v.Title, buffer)
buffer.WriteString(embed__3)
}
if v.ImageURL != "" {
buffer.WriteString(embed__11)
- WriteAll(v.ImageURL, true, buffer)
+ WriteEscString(v.ImageURL, buffer)
buffer.WriteString(embed__3)
}
if v.VideoURL != "" {
buffer.WriteString(embed__13)
- WriteAll(v.Width, true, buffer)
+ WriteInt(int64(v.Width), buffer)
buffer.WriteString(embed__14)
- WriteAll(v.Height, true, buffer)
+ WriteInt(int64(v.Height), buffer)
buffer.WriteString(embed__15)
- WriteAll(v.VideoURL, true, buffer)
+ WriteEscString(v.VideoURL, buffer)
buffer.WriteString(embed__16)
}
@@ -64,37 +66,37 @@ func Embed(v *ViewsData, buffer *pool.ByteBuffer) {
buffer.WriteString(embed__17)
}
buffer.WriteString(embed__1)
- WriteAll(v.URL, true, buffer)
+ WriteEscString(v.URL, buffer)
buffer.WriteString(embed__2)
- WriteAll(v.Description, true, buffer)
+ WriteEscString(v.Description, buffer)
buffer.WriteString(embed__3)
if v.ImageURL != "" {
buffer.WriteString(embed__18)
- WriteAll(v.ImageURL, true, buffer)
+ WriteEscString(v.ImageURL, buffer)
buffer.WriteString(embed__3)
}
if v.VideoURL != "" {
buffer.WriteString(embed__20)
- WriteAll(v.VideoURL, true, buffer)
+ WriteEscString(v.VideoURL, buffer)
buffer.WriteString(embed__21)
- WriteAll(v.VideoURL, true, buffer)
+ WriteEscString(v.VideoURL, buffer)
buffer.WriteString(embed__22)
- WriteAll(v.Width, true, buffer)
+ WriteInt(int64(v.Width), buffer)
buffer.WriteString(embed__23)
- WriteAll(v.Height, true, buffer)
+ WriteInt(int64(v.Height), buffer)
buffer.WriteString(embed__3)
}
if v.OEmbedURL != "" {
buffer.WriteString(embed__25)
- WriteAll(v.OEmbedURL, false, buffer)
+ buffer.WriteString(v.OEmbedURL)
buffer.WriteString(embed__26)
- WriteAll(v.Title, true, buffer)
+ WriteEscString(v.Title, buffer)
buffer.WriteString(embed__3)
}
buffer.WriteString(embed__4)
- WriteAll(`0; url = `+v.URL+``, true, buffer)
+ WriteEscString(`0; url = `+v.URL+``, buffer)
buffer.WriteString(embed__5)
- WriteAll(v.URL, true, buffer)
+ WriteEscString(v.URL, buffer)
buffer.WriteString(embed__6)
}
diff --git a/views/home.jade.go b/views/home.jade.go
index 09c6760..510c89f 100644
--- a/views/home.jade.go
+++ b/views/home.jade.go
@@ -7,7 +7,7 @@ import (
)
const (
- home__0 = `
InstaFixInstaFix
Fix Instagram embeds in Discord (and Telegram!)
InstaFix serves fixed Instagram image and video embeds. Heavily inspired by fxtwitter.com.
How to Use
- Add dd before instagram.com to fix embeds.
- `
+ home__0 = `InstaFix
InstaFix
Fix Instagram embeds in Discord (and Telegram!)
InstaFix serves fixed Instagram image and video embeds. Heavily inspired by fxtwitter.com.
How to Use
- Add dd before instagram.com to fix embeds, or
- `
home__1 = `
Source code available in GitHub!
• Instagram is a trademark of Instagram, Inc. This app is not affiliated with Instagram, Inc.`
)
diff --git a/views/model.go b/views/model/model.go
similarity index 95%
rename from views/model.go
rename to views/model/model.go
index 19c588e..bfcf080 100644
--- a/views/model.go
+++ b/views/model/model.go
@@ -1,4 +1,4 @@
-package views
+package model
type ViewsData struct {
Card string
diff --git a/views/oembed.manual.go b/views/oembed.manual.go
index 5dd671a..8770b5d 100644
--- a/views/oembed.manual.go
+++ b/views/oembed.manual.go
@@ -2,7 +2,11 @@
package views
-import pool "github.com/valyala/bytebufferpool"
+import (
+ "instafix/views/model"
+
+ pool "github.com/valyala/bytebufferpool"
+)
const (
oembed__0 = `{"author_name": `
@@ -10,7 +14,7 @@ const (
oembed__2 = `","provider_name": "InstaFix","provider_url": "https://github.com/Wikidepia/InstaFix","title": "Instagram","type": "link","version": "1.0"}`
)
-func OEmbed(o *OEmbedData, buffer *pool.ByteBuffer) {
+func OEmbed(o *model.OEmbedData, buffer *pool.ByteBuffer) {
buffer.WriteString(oembed__0)
WriteAll(o.Text, false, buffer) // Escape in handlers