b2b48f61b0
* [WIP] Torrent Generation on not found error As asked in #1517, it allows on-the-fly torrent generation. Since it uses magnet links, it needs some time to connect to peers. So it can't be instant generation, we need the user to wait and try after a minute at least. * Replace Fatal by simple error * attempt at fixing travis * del * Add Anacrolyx dependency * Add back difflib * Remove .torrent suffix in the url example * Add some explanations when file missing page shown * Ignore downloads directory * Either use cache (third-party site) or own download directory * Wrong import * If there is an error then it means we aren't generating a torrent file May it be "torrent not found" or "We do not store torrent files" which are the two only existing errors for this page * hash is never empty * TorrentLink may be empty at times So we add a /download/:hash link if it is * Update README.md * Made a mistake here, need to check if false * Update en-us.all.json * Update CHANGELOG.md * Torrent file generation can be triggered by click on button if JS enabled * Update download.go * Update download.go * Use c.JSON instead of text/template * Return to default behavior if we don't generate the file * Don't do the query if returned to default behavior * Add "Could not generate torrent file" error * Fix JS condition & lower delay until button updates * Start download automatically once torrent file is generated * Fix torrentFileExists() constantly returning false if external torrent download URL * torrent-view-data is two tables instead of one This allows the removal of useless things without any problem (e.g Website link), but also a better responsibe design since the previous one separated stats after a certain res looking very wonky * CSS changes to go along * Remove useless <b></b> * Update main.css * In torrentFileExists, check if filestorage path exists instead of looking at the domain in torrent link When checking if the file is stored on another server i used to simply check if the domain name was inside the torrent link, but we can straight up check for filestorage length * Fix JS of on-demand stat fetching * ScrapeAge variable accessible through view.jet.html Contains last scraped time in hours, is at -1 is torrent has never been scraped Stats will get updated if it's either at -1 or above 1460 (2 months old) * Refresh stats if older than two months OR unknown and older than 24h Show last scraped date even if stats are unknown * Add StatsObsolete variable to torrent Indicating if: - They can be shown - They need to be updated * Update scraped data even if Unknown, prevent users from trying to fetch stats every seconds * Torrent file stored locally by default * no need to do all of that if no filestorage * fix filestorage path * Fix torrent download button stuck on "Generating torrent file" at rare times * fix some css rules that didn't work on IE * Fix panic error Seems like this error is a known bug from anacrolyx torrent https://github.com/anacrolix/torrent/issues/83 To prevent it, I'm creating a single client and modifying the socket.go to make it not raise a panic but a simple error log. |
||
---|---|---|
.. | ||
admin | ||
errors | ||
layouts | ||
site | ||
helpers.go | ||
README.md | ||
template.go | ||
template_functions.go | ||
template_functions_test.go | ||
template_test.go |
How-To Template
Templating system is based on CloudyKit Jet Template. Therefore it is very much like the Golang basic template system but with some improvements. For all syntaxic question, it is recommanded to look into Jet Template documentation here.
File naming
You can, pretty much, name your files however you want. But, to keep some homogenuity, it would be preferable to keep the name in lowercase, you can use underscores and you have to use the suffix ".jet.html"
Global Variables
In every template file, besides the built-in functions from Jet Template, you have also some Nyaa Global Variables that you can access to. Those variables are set in template.go
in CommonVariable function. If you want to add a global variable, it is there. Be aware to set only important variables here, not page specific one.
What do they do?
Here we will try to look into each variable and explain how do they work.
Config
variable is the website configuration set in config/config.yml. You can access every exported Properties and functions fromconfig/struct.go
. For example, Config.Torrents.Tags.Default return the default tag type and Config.Port return the running port.CsrfToken
variable return a string for the csrf input field. You have to use it in a hidden input every time you want to make a POST request.Errors
variable is a map[string][] with all the errors listed, from an internal error to a more simple form input error. Better to use the yield functionerrors()
.Infos
variable is a map[string][] with all the information messages listed. Better to use the yield functioninfos()
.Mascot
variable is the choosen mascot.MascotURL
variable is the url of the mascot set by the user.Search
variable is link to the search form state. For example, you can access to the set category withSearch.Category
. This variables also inherit all exported Properties fromTorrentParam
(utils/search/torrentParam.go).Theme
variable is the name of the choosen theme.URL
variable is the current URL of the page. This variable is a net/url.Url struct. Therefore you can use all exported properties and functions from it. More information in the golang doc.User
variable is the current User. This variable is defined in models/user.go. Every exported properties and functions are available. For example,User.Username
gives you the user's username andUser.IsModerator()
tells you if a user is a moderator or not.
How to use them?
Pretty simple, just type: {{ NameOfVariable }}
. For example, {{ URL.String() }} to get the current URL.
Global Functions
Same as global variables, there are also global functions. They are all defined here.
contains(language, string)
tells you if a language corresponds to the language code providedgenActivityContent(activity, T function)
returns the translated activty.genUploaderLink(uploaderID, uploaderName, hidden)
return a<a href="">Username</a>
for the user provided based on the elements provided. For example, if you provide a username and no userID or a hidden bool to true. Then it won't return a link but will return "renchon" username.getCategory(MainCategory, keepParent)
return an array ofCategory
(struct set in utils/categories/categories.go) based on the MainCategory string provided and the bool keepParent. If keepParent is true, the MainCategory is included.categoryName(maincat, subcat)
returns the category nameSukebei()
returns a boolean, true if the website is sukebei, false if not And many more...
How to use them?
Same as global variables, just do {{ function() }}
. For example, flagCode("fr-fr")
returns the flag code "fr".
Helpers Functions
Beside global functions accessible whenever you want, you can also import template functions or make them.
All template functions beside the global ones, should be set in separate files in /templates/layouts/partials/helpers/
.
List of template functions available (non exhaustive, please look for them in helpers folder):
badge_user()
is a function used in menu to display the user badgecaptcha(captchaid)
is a function used in forms to display a captcha input, it needs a captchaid to workcsrf_field()
is a function used in forms to add a hidden input for the csrf check. The token is directly taken from the global variableserrors(name)
is a function used to display the error messages. You just need to specify what errors do you want.infos(name)
is a function used to display the informations messages. You just to specify what infos do you want.
How to use them?
A bit less easy, you need to use this format: {{ yield function(param="something") }}
. For example, {{ yield csrf_field() }}
will add a csrf hidden input or {{ errors(name="Description") }}
will display all the errors for Description.
Furthermore, you need to import (relative to /templates/) the file where the function is defined at the start of template! For example, {{ import "layouts/partials/helpers/csrf" }}
to import the csrf_field() function and use it.