Compare commits

..

3 Commits

Author SHA1 Message Date
httpjamesm 72a7392142 Merge branch 'main' into concurrency-improvements 2023-08-21 01:08:06 -04:00
httpjamesm 1f77bf4ed6 Merge branch 'main' into concurrency-improvements 2023-08-21 01:07:02 -04:00
httpjamesm 50fc162b47 refactor: concurrently proxy img tags 2023-08-21 01:04:11 -04:00
4 changed files with 25 additions and 29 deletions
-6
View File
@@ -1,6 +0,0 @@
{
"trailingComma": "es5",
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
+4 -3
View File
@@ -10,7 +10,7 @@
--link-color: #92adff;
}
[data-theme='light'] {
[data-theme="light"] {
--main-bg: rgb(219, 219, 219);
--text-color: #000;
--muted-text-color: #636363;
@@ -26,6 +26,7 @@ a {
color: var(--link-color);
}
html {
margin: 0;
padding: 0;
@@ -44,9 +45,9 @@ html {
.icon img {
background: white;
border-radius: 50%;
padding: 0.25rem;
padding: .25rem;
}
details {
cursor: pointer;
}
}
+5 -13
View File
@@ -19,17 +19,9 @@ body {
box-sizing: border-box;
}
@media (orientation: landscape) {
.parent {
max-width: 50%;
width: fit-content;
}
}
@media (orientation: portrait) {
.parent {
max-width: 90%;
width: fit-content;
}
.parent {
max-width: 90%;
width: fit-content;
}
.header {
@@ -39,7 +31,7 @@ body {
.card-tags {
display: flex;
gap: 0.5rem;
gap: .5rem;
}
.card-tags .tag {
@@ -102,7 +94,7 @@ img {
margin-bottom: 1rem;
background-color: var(--meta-bg);
color: var(--text-color);
display: flex;
justify-content: space-between;
align-items: center;
+16 -7
View File
@@ -6,6 +6,7 @@ import (
"os"
"regexp"
"strings"
"sync"
"time"
"github.com/golang-jwt/jwt/v4"
@@ -14,20 +15,28 @@ import (
var imgTagRegex = regexp.MustCompile(`<img[^>]*\s+src\s*=\s*"(.*?)"[^>]*>`)
func ReplaceImgTags(inHtml string) string {
// find all img tags
imgTags := imgTagRegex.FindAllString(inHtml, -1)
var wg sync.WaitGroup
var mu sync.Mutex
for _, imgTag := range imgTags {
// parse the src="" attribute
srcRegex := regexp.MustCompile(`src\s*=\s*"(.*?)"`)
src := srcRegex.FindStringSubmatch(imgTag)[1]
wg.Add(1)
go func(imgTag string) {
defer wg.Done()
srcRegex := regexp.MustCompile(`src\s*=\s*"(.*?)"`)
src := srcRegex.FindStringSubmatch(imgTag)[1]
authToken, _ := generateImageProxyAuth(src)
authToken, _ := generateImageProxyAuth(src)
// replace the img tag with a proxied url
inHtml = strings.Replace(inHtml, imgTag, fmt.Sprintf(`<img src="%s/proxy?auth=%s">`, os.Getenv("APP_URL"), authToken), 1)
mu.Lock()
defer mu.Unlock()
inHtml = strings.Replace(inHtml, imgTag, fmt.Sprintf(`<img src="%s/proxy?auth=%s">`, os.Getenv("APP_URL"), authToken), 1)
}(imgTag)
}
wg.Wait()
return inHtml
}