Fix callback URL rewrite
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m28s
All checks were successful
Automated Container Build / build-and-push (push) Successful in 1m28s
This commit is contained in:
parent
360cb5275a
commit
3e19cae267
2 changed files with 11 additions and 3 deletions
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"git.elijahkuntz.com/Elijah/drive/config"
|
"git.elijahkuntz.com/Elijah/drive/config"
|
||||||
"git.elijahkuntz.com/Elijah/drive/middleware"
|
"git.elijahkuntz.com/Elijah/drive/middleware"
|
||||||
|
|
@ -48,8 +49,15 @@ func (h *OnlyOfficeHandler) Callback(c *fiber.Ctx) error {
|
||||||
return c.Status(400).JSON(fiber.Map{"error": "url required"})
|
return c.Status(400).JSON(fiber.Map{"error": "url required"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the server cannot resolve the public URL due to hairpin NAT,
|
||||||
|
// we can rewrite it to use the internal Docker IP
|
||||||
|
downloadUrl := req.Url
|
||||||
|
if strings.HasPrefix(downloadUrl, "https://office.elijahkuntz.com") {
|
||||||
|
downloadUrl = strings.Replace(downloadUrl, "https://office.elijahkuntz.com", "http://192.168.50.81:8084", 1)
|
||||||
|
}
|
||||||
|
|
||||||
// Download modified file from Document Server
|
// Download modified file from Document Server
|
||||||
resp, err := http.Get(req.Url)
|
resp, err := http.Get(downloadUrl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c.Status(500).JSON(fiber.Map{"error": "failed to download file"})
|
return c.Status(500).JSON(fiber.Map{"error": "failed to download file"})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -473,7 +473,7 @@ class ApiClient {
|
||||||
async createOnlyOfficeFile(type: 'word' | 'slide') {
|
async createOnlyOfficeFile(type: 'word' | 'slide') {
|
||||||
const res = await this.request('/api/onlyoffice/create', {
|
const res = await this.request('/api/onlyoffice/create', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ type })
|
body: { type }
|
||||||
});
|
});
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
@ -481,7 +481,7 @@ class ApiClient {
|
||||||
async signOnlyOfficeConfig(config: any) {
|
async signOnlyOfficeConfig(config: any) {
|
||||||
const res = await this.request('/api/onlyoffice/sign', {
|
const res = await this.request('/api/onlyoffice/sign', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(config)
|
body: config
|
||||||
});
|
});
|
||||||
return res.json();
|
return res.json();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Reference in a new issue