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

view STL files 2 #16352

Closed
2 of 6 tasks
raidenlal opened this issue Jul 6, 2021 · 10 comments
Closed
2 of 6 tasks

view STL files 2 #16352

raidenlal opened this issue Jul 6, 2021 · 10 comments
Labels
type/docs This PR mainly updates/creates documentation type/question Issue needs no code to be fixed, only a description on how to fix it yourself.

Comments

@raidenlal
Copy link

raidenlal commented 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: #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?

@noerw
Copy link
Member

noerw commented 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 noerw added type/docs This PR mainly updates/creates documentation type/question Issue needs no code to be fixed, only a description on how to fix it yourself. labels Jul 10, 2021
@raidenlal
Copy link
Author

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.

@noerw
Copy link
Member

noerw commented 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

@raidenlal
Copy link
Author

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
Copy link
Author

raidenlal commented 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?

@noerw
Copy link
Member

noerw commented 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.

@raidenlal
Copy link
Author

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.

@zeripath
Copy link
Contributor

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.

@raidenlal
Copy link
Author

raidenlal commented 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
Copy link
Author

raidenlal commented 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.

@go-gitea go-gitea locked and limited conversation to collaborators May 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type/docs This PR mainly updates/creates documentation type/question Issue needs no code to be fixed, only a description on how to fix it yourself.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants