Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting issue on TOML and text files links - Newlines removed #14

Open
damascene opened this issue May 7, 2024 · 7 comments
Open

Comments

@damascene
Copy link

Storing files using paste.toml as name and TOML content produces a link to file that displays non valid TOML file with all new lines removed. I've noticed similar issue with text format also. JSON files with .json extension are displayed correctly.

Original toml:

# This is a TOML document

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[database]
enabled = true
ports = [ 8000, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }

[servers]

[servers.alpha]
ip = "10.0.0.1"
role = "frontend"

[servers.beta]
ip = "10.0.0.2"
role = "backend"

Result on the link:

# This is a TOML document title = "TOML Example" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 [database] enabled = true ports = [ 8000, 8001, 8002 ] data = [ ["delta", "phi"], [3.14] ] temp_targets = { cpu = 79.5, case = 72.0 } [servers] [servers.alpha] ip = "10.0.0.1" role = "frontend" [servers.beta] ip = "10.0.0.2" role = "backend" 

However using the load button inside the editor can still retrieve a well formatted toml file. Issue seems is when you open the file link.

https://nosdav.net/...................../paste.toml

I've tested with json file and there was no issue.

@melvincarvalho
Copy link
Contributor

Thanks, I dont yet support .toml mime type, which are listed here:

https://github.com/nosdav/server/blob/gh-pages/index.js#L50

I'll try and fix this later today and redeploy the server

@melvincarvalho
Copy link
Contributor

I looked at this a bit more, actually it's saving fine, its just the browser displays text like that without newlines

see:

https://nosdav.net/de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645/test.toml

But if you view browser source you get

image

Also try

curl https://nosdav.net/de7ecd1e2976a6adb2ffa5f4db81a7d812c8bb6698aa00dcf1e76adb55efd645/test.toml
# This is a TOML document

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[database]
enabled = true
ports = [ 8000, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }

[servers]

[servers.alpha]
ip = "10.0.0.1"
role = "frontend"

[servers.beta]
ip = "10.0.0.2"

So this should be working

@damascene
Copy link
Author

I've compared the source of the web pages between Nosdav and gitlab snippet and found that snippests and other services shows the plain content while Nosdav render it differently:

The content are inserted in html tags. Your test.toml file after saving from the webpage.

<html><head>
<meta http-equiv="content-type" content="text/html; charset=windows-1252"></head><body># This is a TOML document

title = "TOML Example"

[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00

[database]
enabled = true
ports = [ 8000, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }

[servers]

[servers.alpha]
ip = "10.0.0.1"
role = "frontend"

[servers.beta]
ip = "10.0.0.2"
role = "backend"</body></html>

the view source shows this:
image

Seems the website is using some type of rendering and not the raw content on the link.

Here is the same content in Gitlab snippet for compression
https://gitlab.com/-/snippets/3708145/raw/main/TOML.toml

@damascene
Copy link
Author

Also notice that content-type is text/html while in snippets it's text/plain; charset=utf-8

@melvincarvalho
Copy link
Contributor

Good info, but it's fundamental to the design of nosdav that users own their own data, and that the system does not change it.

While gitlab understandably offers some quality of life enhancements for toml files (and .md) I dont think the core of nosdav should do that. I could be persuaded otherwise, but I am unsure right now that is a good thing to change.

There are other ways to do this, based on the architecture. Since NosDAV builds on REST, see: Layered System then it is possible to layer on some middleware to add something based on the mime type, if that system needs it.

Similarly a small script in a reverse proxy could insert some HTML tags. But I think the core of NosDAV should be to maintain the integrity of the data, which is a REST principle.

That said, a NAV for this use case could be developed if there is enough interest.

Does that make sense to you?

@melvincarvalho
Copy link
Contributor

Also notice that content-type is text/html while in snippets it's text/plain; charset=utf-8

Yes, that could be fixed, do you know the correct mime type of .toml? My research shows me it is application/toml but im not 100% sure. But this might trigger a download from the browser, which might even be a worse UX.

@damascene
Copy link
Author

My research shows me it is application/toml but im not 100% sure.

True. https://toml.io/en/v0.5.0#mime-type

The link says "file" with download icon so I supposed that is what it should be doing, right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants