Albirew/nyaa-pantsu
Albirew
/
nyaa-pantsu
Archivé
1
0
Bifurcation 0
Ce dépôt a été archivé le 2022-05-07. Vous pouvez voir ses fichiers ou le cloner, mais pas ouvrir de ticket ou de demandes d'ajout, ni soumettre de changements.
nyaa-pantsu/templates
kilo d5c2c6b676 Upload to nyaa.si, anidex & TokyoTosho [done] (#1633)
* Update upload.go

* Update helpers.go

* Update template_test.go

* Update upload_multiple.jet.html

* change variable names

* wrong copypaste

* change variable name

* ditto

* Fix travis

* Update main.css

* Update upload.go

* Update upload.jet.html

* Update main.css

* Update upload.go

* More compact form

* CSS changes to go along

* Update main.css

* Update upload.jet.html

* Slightly lower bottom margin

* Update upload_multiple.jet.html

* tomorrow color adjustements

* small css adjustements

* Update upload.go

* Update default_config.yml

* Update default_config.yml

* Update structs.go

* Update user.go

* Update structs.go

* Update upload.go

* Update default_config.yml

* Update upload_multiple.jet.html

* Update upload.go

* Update upload.jet.html

* Update template_test.go

* this one is optional for anidex

* Update default_config.yml

* Possible improvement
As mentionned in my comment, it seems that having a checkbox already checked and disabled for logged in user + having the input text for apikey is a bit tedious.
Moreover, asking to check and fill the input text to upload in anidex when you are not logged is doing things twice. If you don't want to upload to anidex, don't fill the input.

So this commit push a new behaviour:
* If you are logged in and you have filled your anidex/nyaasi api key : the form should only show the checkbox asking if you want to upload to nyaasi.
* If you're not logged in or you don't have filled your api key in your profile settings: you only show the input text for the api key and not the checkbox. If someone wants to upload to nyaasi/anidex, he will just need to fill the input.

* This adds back the support of anonymous upload when logged in or not.
This works simply by checking if the user wants to upload as anon (when he checks the checkbox "upload as anonymous") or by checking the emptyness of apikey.
+ reverts the condition statements since it was needed to have apikey empty

* Forgot to save this file

* This commit adds the go routines for each upload service (anidex, nyaasi, tosho).
New controller and url to check the upload status (/upload/status/:id).
If you add ?json at the end, it outputs a json format of the multi upload status.
To prevent memory overload, we only keep in memory the multiupload status for 5 minutes.
Moved multipleform struct from templates to upload utils.

* fix form display on classic theme

* This commit adds:
* Javascript refreshing of the upload status
* Localization of the pages
* Fixed some bugs

This works, only need to get torrent file now.

* Added a new function to get the Path to the torrent file.

* Added a function to check that a torrent file exists and if not generate it on multiupload

* Enabled file upload through http post request to anidex

* Fixed bugs

* Modified the behaviour to generate torrent preivously. It is a synchrone function now. So we need to make it asynchronous in download.go

Now torrents file are always generated at upload time in a background processus with the correct trackers (needed ones + the ones provided by the user).
I made the anidex tracker as a needed one to allow multiupload even if the user hasn't included in his torrent file/magnet url.

* Moving deadtrackers list to default config
Support torrent file creation when upload without scraping
* Fix possible bug where no one is seeding a torrent yet (first time upload)
Add primary tracker in torrent file

* Fixing issue with boolean pointer for private torrent

* fixing index out of range for announcelist filtering
Fixing anidex tracker not found

* Fixing lang id error

* Anidex upload works

* Fix for multiupload with magnet

* This adds TokyoTosho support. Since TokyoTosho API only support upload by URL (and not torrent file upload). We need to make the download url available without ddos protection.

Also TokyoTosho doesn't need a category select. Since it does have limited option, we can automatically convert our categories to the tokyotosho one.

* Removing the folder tosho and put categories.go directly in upload package.
Added category conversion for nyaasi too.
Added tests on category conversion.

* This should add nyaasi support.
Is not tested though.

* Updated defaut config with new nyaa.si behaviour?

* Forgot to commit this file
2018-01-03 18:21:07 +10:00
..
admin Upload to nyaa.si, anidex & TokyoTosho [done] (#1633) 2018-01-03 18:21:07 +10:00
errors Janitor (#1728) 2017-11-14 09:39:39 +01:00
layouts Search page title function & Fix ES (#1745) 2017-11-23 12:20:14 +01:00
site Upload to nyaa.si, anidex & TokyoTosho [done] (#1633) 2018-01-03 18:21:07 +10:00
README.md Update README.md (#1432) 2017-08-28 20:46:13 +02:00
helpers.go Things (#1740) 2017-11-20 11:13:00 +10:00
template.go Things (#1740) 2017-11-20 11:13:00 +10:00
template_functions.go Search page title function & Fix ES (#1745) 2017-11-23 12:20:14 +01:00
template_functions_test.go Search page title function & Fix ES (#1745) 2017-11-23 12:20:14 +01:00
template_test.go Upload to nyaa.si, anidex & TokyoTosho [done] (#1633) 2018-01-03 18:21:07 +10:00

README.md

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 from config/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 function errors().
  • Infos variable is a map[string][] with all the information messages listed. Better to use the yield function infos().
  • 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 with Search.Category. This variables also inherit all exported Properties from TorrentParam (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 and User.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 provided
  • genActivityContent(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 of Category (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 name
  • Sukebei() 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 badge
  • captcha(captchaid) is a function used in forms to display a captcha input, it needs a captchaid to work
  • csrf_field() is a function used in forms to add a hidden input for the csrf check. The token is directly taken from the global variables
  • errors(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.