view STL files 2 #7548

Closed
opened 2025-11-02 07:29:28 -06:00 by GiteaMirror · 10 comments
Owner

Originally created by @raidenlal on GitHub (Jul 6, 2021).

  • Gitea version (or commit ref): 1.15.0+dev-541-g5bb97a12d
  • Git version: UI related
  • Operating system: docker container using gitea/gitea:latest
  • Database (use [x]):
    • PostgreSQL
    • MySQL
    • MSSQL
    • SQLite
  • Can you reproduce the bug at https://try.gitea.io:
    • Yes (provide example URL)
    • No
  • Log gist:

Description

Continuing discussion from previous issue: https://github.com/go-gitea/gitea/issues/5979
This would be really nice thing to have out of box, but okay I have followed proposed solution: "I will close this issue as it can be setup by many ways and at least one is in docs."

I looked at the docu:
https://docs.gitea.io/en-us/customizing-gitea/#example-stl-preview
Link there to https://jinjunho.github.io/Madeleine.js/ is no longer working, so google found some other repo of the project: https://github.com/beige90/Madeleine.js However last commit there is 7 years ago, feels abandoned.

So I have mapped required directories from the container to host machine and put required stuff according to the docs:

bash-5.1# pwd
/usr/share/git-core/public/Madeleine.js
bash-5.1# ls
LICENSE    README.md  css        examples   images     models     src

And the template:

bash-5.1# pwd
/usr/share/git-core/templates/custom
bash-5.1# ls
footer.tmpl
bash-5.1# cat footer.tmpl 
<script>
  function lS(src) {
    return new Promise(function (resolve, reject) {
      let s = document.createElement("script");
      s.src = src;
      s.addEventListener("load", () => {
        resolve();
      });
      document.body.appendChild(s);
    });
  }

  if ($('.view-raw>a[href$=".stl" i]').length) {
    $("body").append(
      '<link href="/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">'
    );
    Promise.all([
      lS("/Madeleine.js/src/lib/stats.js"),
      lS("/Madeleine.js/src/lib/detector.js"),
      lS("/Madeleine.js/src/lib/three.min.js"),
      lS("/Madeleine.js/src/Madeleine.js"),
    ]).then(function () {
      $(".view-raw")
        .attr("id", "view-raw")
        .attr("style", "padding: 0;margin-bottom: -10px;");
      new Madeleine({
        target: "view-raw",
        data: $('.view-raw>a[href$=".stl" i]').attr("href"),
        path: "/Madeleine.js/src",
      });
      $('.view-raw>a[href$=".stl"]').remove();
    });
  }
</script>

And result is:
image

Any ideas?

Originally created by @raidenlal on GitHub (Jul 6, 2021). - Gitea version (or commit ref): 1.15.0+dev-541-g5bb97a12d - Git version: UI related - Operating system: docker container using gitea/gitea:latest - Database (use `[x]`): - [ ] PostgreSQL - [ ] MySQL - [ ] MSSQL - [X] SQLite - Can you reproduce the bug at https://try.gitea.io: - [ ] Yes (provide example URL) - [X] No - Log gist: <!-- It really is important to provide pertinent logs --> <!-- Please read https://docs.gitea.io/en-us/logging-configuration/#debugging-problems --> <!-- In addition, if your problem relates to git commands set `RUN_MODE=dev` at the top of app.ini --> ## Description Continuing discussion from previous issue: https://github.com/go-gitea/gitea/issues/5979 This would be really nice thing to have out of box, but okay I have followed proposed solution: "I will close this issue as it can be setup by many ways and **at least one is in docs**." I looked at the docu: https://docs.gitea.io/en-us/customizing-gitea/#example-stl-preview Link there to https://jinjunho.github.io/Madeleine.js/ is no longer working, so google found some other repo of the project: https://github.com/beige90/Madeleine.js However last commit there is 7 years ago, feels abandoned. So I have mapped required directories from the container to host machine and put required stuff according to the docs: ``` bash-5.1# pwd /usr/share/git-core/public/Madeleine.js bash-5.1# ls LICENSE README.md css examples images models src ``` And the template: ``` bash-5.1# pwd /usr/share/git-core/templates/custom bash-5.1# ls footer.tmpl bash-5.1# cat footer.tmpl <script> function lS(src) { return new Promise(function (resolve, reject) { let s = document.createElement("script"); s.src = src; s.addEventListener("load", () => { resolve(); }); document.body.appendChild(s); }); } if ($('.view-raw>a[href$=".stl" i]').length) { $("body").append( '<link href="/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">' ); Promise.all([ lS("/Madeleine.js/src/lib/stats.js"), lS("/Madeleine.js/src/lib/detector.js"), lS("/Madeleine.js/src/lib/three.min.js"), lS("/Madeleine.js/src/Madeleine.js"), ]).then(function () { $(".view-raw") .attr("id", "view-raw") .attr("style", "padding: 0;margin-bottom: -10px;"); new Madeleine({ target: "view-raw", data: $('.view-raw>a[href$=".stl" i]').attr("href"), path: "/Madeleine.js/src", }); $('.view-raw>a[href$=".stl"]').remove(); }); } </script> ``` And result is: ![image](https://user-images.githubusercontent.com/53146816/124613060-25b29d00-de73-11eb-878d-60d175f123bf.png) Any ideas?
GiteaMirror added the type/questiontype/docs labels 2025-11-02 07:29:28 -06:00
Author
Owner

@noerw commented on GitHub (Jul 10, 2021):

I didn't try this myself, but I'd check the network tab in your browsers developer tools, and see if all requests could be resolved, and what errors are visible in the console.

It could also be that the JS just doesn't match how gitea renders the page anymore.
In any case, it would be nice if you send a PR updating the docs, once you get it to work :)

@noerw commented on GitHub (Jul 10, 2021): I didn't try this myself, but I'd check the network tab in your browsers developer tools, and see if all requests could be resolved, and what errors are visible in the console. It could also be that the JS just doesn't match how gitea renders the page anymore. In any case, it would be nice if you send a PR updating the docs, once you get it to work :)
Author
Owner

@raidenlal commented on GitHub (Jul 10, 2021):

Console does not contain any errors and there are no failed requests. It looks like the new template is just being completely ignored - thats why I did provide the complete file listings in the issue - in case some file was misplaced or something.

@raidenlal commented on GitHub (Jul 10, 2021): Console does not contain any errors and there are no failed requests. It looks like the new template is just being completely ignored - thats why I did provide the complete file listings in the issue - in case some file was misplaced or something.
Author
Owner

@noerw commented on GitHub (Jul 10, 2021):

Ah, I didn't check the paths too thoroughly.
Are you sure /usr/share/git-core is your gitea custom path? If it's your base gitea working directory, this would be the right path:

- /usr/share/git-core/templates/custom/
- /usr/share/git-core/public/
+ /usr/share/git-core/custom/templates/custom/
+ /usr/share/git-core/custom/public/

If you're using the default dockerfile, the base path is /data/gitea. → So /data/gitea/custom/templates/custom etc

@noerw commented on GitHub (Jul 10, 2021): Ah, I didn't check the paths too thoroughly. Are you sure `/usr/share/git-core` is your gitea custom path? If it's your base gitea working directory, this would be the right path: ```diff - /usr/share/git-core/templates/custom/ - /usr/share/git-core/public/ + /usr/share/git-core/custom/templates/custom/ + /usr/share/git-core/custom/public/ ``` If you're using the default dockerfile, the base path is `/data/gitea`. → So `/data/gitea/custom/templates/custom` etc
Author
Owner

@raidenlal commented on GitHub (Jul 10, 2021):

I am using default docker image. So I have tried to put it into /data, like so:

bash-5.1# ls -la
total 0
drwxrwxrwx    1 root     root           512 Jul 10 10:30 .
drwxr-xr-x    1 git      git            512 Jul 10 10:30 ..
drwxrwxrwx    1 root     root           512 Jul 10 10:30 public
drwxrwxrwx    1 root     root           512 Jul 10 10:29 templates
bash-5.1# ls -la public/
total 0
drwxrwxrwx    1 root     root           512 Jul 10 10:30 .
drwxrwxrwx    1 root     root           512 Jul 10 10:30 ..
drwxrwxrwx    1 root     root           512 Jul 10 10:30 Madeleine.js
bash-5.1# ls -la templates/custom/
total 4
drwxrwxrwx    1 root     root           512 Jul 10 10:29 .
drwxrwxrwx    1 root     root           512 Jul 10 10:29 ..
-rwxrwxrwx    1 root     root          1018 Jul  6 13:45 footer.tmpl
bash-5.1# pwd
/data/gitea/custom

but this is not working either.

@raidenlal commented on GitHub (Jul 10, 2021): I am using default docker image. So I have tried to put it into /data, like so: ``` bash-5.1# ls -la total 0 drwxrwxrwx 1 root root 512 Jul 10 10:30 . drwxr-xr-x 1 git git 512 Jul 10 10:30 .. drwxrwxrwx 1 root root 512 Jul 10 10:30 public drwxrwxrwx 1 root root 512 Jul 10 10:29 templates bash-5.1# ls -la public/ total 0 drwxrwxrwx 1 root root 512 Jul 10 10:30 . drwxrwxrwx 1 root root 512 Jul 10 10:30 .. drwxrwxrwx 1 root root 512 Jul 10 10:30 Madeleine.js bash-5.1# ls -la templates/custom/ total 4 drwxrwxrwx 1 root root 512 Jul 10 10:29 . drwxrwxrwx 1 root root 512 Jul 10 10:29 .. -rwxrwxrwx 1 root root 1018 Jul 6 13:45 footer.tmpl bash-5.1# pwd /data/gitea/custom ``` but this is not working either.
Author
Owner

@raidenlal commented on GitHub (Jul 10, 2021):

I have also tried the other way:

bash-5.1# ls /usr/share/git-core/custom/templates/custom/
footer.tmpl
bash-5.1# ls /usr/share/git-core/custom/public/Madeleine.js
LICENSE    README.md  css        examples   images     models     src

After each moving/copying of the files I did restart the container and deleted browser data.

It looks like you were correct with the default dockerfile:

bash-5.1# echo $GITEA_CUSTOM
/data/gitea
bash-5.1# ls -l /data/gitea
total 1604
drwxrwxrwx    1 git      git            512 Jun 26 13:21 attachments
drwxrwxrwx    1 git      git            512 Jan 12 14:21 avatars
drwxrwxrwx    1 git      git            512 Jan 12 12:58 conf
drwxrwxrwx    1 root     root           512 Jul 10 10:30 custom
-rwxrwxrwx    1 git      git        1642496 Jul 10 10:37 gitea.db
drwxrwxrwx    1 git      git            512 Jan 12 15:57 indexers
drwxr-xr-x    1 git      git            512 Jun 17 22:56 jwt
drwxrwxrwx    1 git      git            512 Jan 12 12:58 log
drwxrwxrwx    1 git      git            512 May 24 15:47 queues
drwxr-xr-x    1 git      git            512 Jun 26 12:13 repo-archive
drwxrwxrwx    1 git      git            512 Jan 12 13:10 repo-avatars
drwxrwxrwx    1 git      git            512 Jul  6 13:48 sessions
drwxrwxrwx    1 git      git            512 Jan 12 15:15 uploads

is there some issue with the folder structure?

@raidenlal commented on GitHub (Jul 10, 2021): I have also tried the other way: ``` bash-5.1# ls /usr/share/git-core/custom/templates/custom/ footer.tmpl bash-5.1# ls /usr/share/git-core/custom/public/Madeleine.js LICENSE README.md css examples images models src ``` After each moving/copying of the files I did restart the container and deleted browser data. It looks like you were correct with the default dockerfile: ``` bash-5.1# echo $GITEA_CUSTOM /data/gitea bash-5.1# ls -l /data/gitea total 1604 drwxrwxrwx 1 git git 512 Jun 26 13:21 attachments drwxrwxrwx 1 git git 512 Jan 12 14:21 avatars drwxrwxrwx 1 git git 512 Jan 12 12:58 conf drwxrwxrwx 1 root root 512 Jul 10 10:30 custom -rwxrwxrwx 1 git git 1642496 Jul 10 10:37 gitea.db drwxrwxrwx 1 git git 512 Jan 12 15:57 indexers drwxr-xr-x 1 git git 512 Jun 17 22:56 jwt drwxrwxrwx 1 git git 512 Jan 12 12:58 log drwxrwxrwx 1 git git 512 May 24 15:47 queues drwxr-xr-x 1 git git 512 Jun 26 12:13 repo-archive drwxrwxrwx 1 git git 512 Jan 12 13:10 repo-avatars drwxrwxrwx 1 git git 512 Jul 6 13:48 sessions drwxrwxrwx 1 git git 512 Jan 12 15:15 uploads ``` is there some issue with the folder structure?
Author
Owner

@noerw commented on GitHub (Jul 10, 2021):

If you're using the official docker image, /data/gitea/custom is the way to go. I don't see how gitea should know about your /usr/share/git-core path.

@noerw commented on GitHub (Jul 10, 2021): If you're using the official docker image, `/data/gitea/custom` is the way to go. I don't see how gitea should know about your `/usr/share/git-core` path.
Author
Owner

@raidenlal commented on GitHub (Jul 11, 2021):

Yes on the last comment I have shown that I tried to put it in the /data/gitea/custom:

bash-5.1# cd /data/gitea/custom
bash-5.1# ls
public     templates
bash-5.1# ls public/
Madeleine.js
bash-5.1# ls templates/
custom
bash-5.1# ls templates/custom/
footer.tmpl
bash-5.1# 

but no STL viewer is still showing.

@raidenlal commented on GitHub (Jul 11, 2021): Yes on the last comment I have shown that I tried to put it in the /data/gitea/custom: ``` bash-5.1# cd /data/gitea/custom bash-5.1# ls public templates bash-5.1# ls public/ Madeleine.js bash-5.1# ls templates/ custom bash-5.1# ls templates/custom/ footer.tmpl bash-5.1# ``` but no STL viewer is still showing.
Author
Owner

@zeripath commented on GitHub (Jul 15, 2021):

Ah you've been affected by the changes in #15219

I've just pushed up some updated documentation.

Files in custom/public are now mounted within assets/ not / so you need to update your templates to account for that.

@zeripath commented on GitHub (Jul 15, 2021): Ah you've been affected by the changes in #15219 I've just pushed up some updated documentation. Files in custom/public are now mounted within `assets/` not `/` so you need to update your templates to account for that.
Author
Owner

@raidenlal commented on GitHub (Jul 15, 2021):

Thanks for the note. I've adjusted my folder structure, but the the wording is confusing - once you mention "custom/public" and then mention "assets" and "/" without mentioning "custom/public".
Now I have:

bash-5.1# ls -la /data/gitea/custom/public/assets/
total 0
drwxrwxrwx    1 root     root           512 Jul 15 22:12 .
drwxrwxrwx    1 root     root           512 Jul 15 22:12 ..
drwxrwxrwx    1 root     root           512 Jul 10 10:30 Madeleine.js
bash-5.1# ls -la /data/gitea/custom/templates/custom/
total 4
drwxrwxrwx    1 root     root           512 Jul 10 10:29 .
drwxrwxrwx    1 root     root           512 Jul 10 10:29 ..
-rwxrwxrwx    1 root     root          1018 Jul  6 13:45 footer.tmpl

The thing is that the javascript library is not even trying to be downloaded by the footer template - so it does not really matter where it is stored at this moment - it seems the root cause is template not working. I don't see any failed http requests in the browser developer console trying to get the Madeleine asset. Or maybe my assumptions are totally wrong - anyways - STL still not showing.

Could you, please, doublecheck my folder structure?

@raidenlal commented on GitHub (Jul 15, 2021): Thanks for the note. I've adjusted my folder structure, but the the wording is confusing - once you mention "custom/public" and then mention "assets" and "/" without mentioning "custom/public". Now I have: ``` bash-5.1# ls -la /data/gitea/custom/public/assets/ total 0 drwxrwxrwx 1 root root 512 Jul 15 22:12 . drwxrwxrwx 1 root root 512 Jul 15 22:12 .. drwxrwxrwx 1 root root 512 Jul 10 10:30 Madeleine.js bash-5.1# ls -la /data/gitea/custom/templates/custom/ total 4 drwxrwxrwx 1 root root 512 Jul 10 10:29 . drwxrwxrwx 1 root root 512 Jul 10 10:29 .. -rwxrwxrwx 1 root root 1018 Jul 6 13:45 footer.tmpl ``` The thing is that the javascript library is not even trying to be downloaded by the footer template - so it does not really matter where it is stored at this moment - it seems the root cause is template not working. I don't see any failed http requests in the browser developer console trying to get the Madeleine asset. Or maybe my assumptions are totally wrong - anyways - STL still not showing. Could you, please, doublecheck my folder structure?
Author
Owner

@raidenlal commented on GitHub (Jul 15, 2021):

Ooooh I get it.
Template is referencing (for example)

    $("body").append(
      '<link href="/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">'
    );

which should be /assets/Madeleine.js/src/css/Madeleine.css?

I've reverted folder structure to:

bash-5.1# ls -l /data/gitea/custom/public/
total 0
drwxrwxrwx    1 root     root           512 Jul 10 10:30 Madeleine.js
bash-5.1# ls -l /data/gitea/custom/templates/custom/
total 4
-rwxrwxrwx    1 root     root          1018 Jul  6 13:45 footer.tmpl

However STL still not showing as if template was ignored. Also BASE_URL/assets/Madeleine.js/src/css/Madeleine.css results in 404 so it seems something is totally wrong.

@raidenlal commented on GitHub (Jul 15, 2021): Ooooh I get it. Template is referencing (for example) ``` $("body").append( '<link href="/Madeleine.js/src/css/Madeleine.css" rel="stylesheet">' ); ``` which should be `/assets/Madeleine.js/src/css/Madeleine.css`? I've reverted folder structure to: ``` bash-5.1# ls -l /data/gitea/custom/public/ total 0 drwxrwxrwx 1 root root 512 Jul 10 10:30 Madeleine.js bash-5.1# ls -l /data/gitea/custom/templates/custom/ total 4 -rwxrwxrwx 1 root root 1018 Jul 6 13:45 footer.tmpl ``` However STL still not showing as if template was ignored. Also BASE_URL/assets/Madeleine.js/src/css/Madeleine.css results in 404 so it seems something is totally wrong.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#7548