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/models/torrent.go

548 lignes
17 KiB
Go
Brut Vue normale Historique

package models
import (
"context"
"errors"
"fmt"
"html/template"
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 09:21:07 +01:00
"os"
"path/filepath"
"reflect"
"strconv"
"strings"
"time"
elastic "gopkg.in/olivere/elastic.v5"
"net/http"
"net/url"
"github.com/NyaaPantsu/nyaa/config"
"github.com/NyaaPantsu/nyaa/utils/cache"
"github.com/NyaaPantsu/nyaa/utils/format"
"github.com/NyaaPantsu/nyaa/utils/log"
"github.com/NyaaPantsu/nyaa/utils/sanitize"
"github.com/bradfitz/slice"
"github.com/fatih/structs"
)
const (
// TorrentStatusNormal Int for Torrent status normal
TorrentStatusNormal = 1
// TorrentStatusRemake Int for Torrent status remake
TorrentStatusRemake = 2
// TorrentStatusTrusted Int for Torrent status trusted
TorrentStatusTrusted = 3
// TorrentStatusAPlus Int for Torrent status a+
TorrentStatusAPlus = 4
// TorrentStatusBlocked Int for Torrent status locked
TorrentStatusBlocked = 5
)
// Torrent model
type Torrent struct {
2017-05-11 00:06:21 +02:00
ID uint `gorm:"column:torrent_id;primary_key"`
Name string `gorm:"column:torrent_name"`
Hash string `gorm:"column:torrent_hash;unique"`
2017-05-11 00:06:21 +02:00
Category int `gorm:"column:category"`
SubCategory int `gorm:"column:sub_category"`
Status int `gorm:"column:status"`
Hidden bool `gorm:"column:hidden"`
2017-05-11 00:06:21 +02:00
Date time.Time `gorm:"column:date"`
UploaderID uint `gorm:"column:uploader"`
Stardom int `gorm:"column:stardom"`
Filesize int64 `gorm:"column:filesize"`
Description string `gorm:"column:description"`
WebsiteLink string `gorm:"column:website_link"`
Trackers string `gorm:"column:trackers"`
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
// Torrent Details
AnidbID uint `gorm:"column:anidbid"`
VndbID uint `gorm:"column:vndbid"`
VgmdbID uint `gorm:"column:vgmdbid"`
Dlsite string `gorm:"column:dlsite"`
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
VideoQuality string `gorm:"column:videoquality"`
AcceptedTags string `gorm:"column:tags"`
// Indicates the language of the torrent's content (eg. subs, dubs, raws, manga TLs)
Language string `gorm:"column:language"`
DeletedAt *time.Time
2017-05-08 19:26:29 +02:00
2017-05-20 13:45:15 +02:00
Uploader *User `gorm:"AssociationForeignKey:UploaderID;ForeignKey:user_id"`
OldUploader string `gorm:"-"` // ???????
2017-05-09 01:56:57 +02:00
OldComments []OldComment `gorm:"ForeignKey:torrent_id"`
Comments []Comment `gorm:"ForeignKey:torrent_id"`
Tags Tags `gorm:"-"`
Scrape *Scrape `gorm:"AssociationForeignKey:ID;ForeignKey:torrent_id"`
FileList []File `gorm:"ForeignKey:torrent_id"`
Languages []string `gorm:"-"` // This is parsed when retrieved from db
}
2017-05-10 19:29:35 +02:00
/* We need a JSON object instead of a Gorm structure because magnet URLs are
not in the database and have to be generated dynamically */
// TorrentJSON for torrent model in json for api
type TorrentJSON struct {
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
ID uint `json:"id"`
Name string `json:"name"`
Status int `json:"status"`
Hidden bool `json:"-"`
Hash string `json:"hash"`
Date string `json:"date"`
FullDate time.Time `json:"-"` //Used to convert the date to full OR short format depending on the situation
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
Filesize int64 `json:"filesize"`
Description template.HTML `json:"description"`
Comments []CommentJSON `json:"comments"`
SubCategory string `json:"sub_category"`
Category string `json:"category"`
// Torrent DBID
AnidbID uint `json:"anidbid"`
VndbID uint `json:"vndbid"`
VgmdbID uint `json:"vgmdbid"`
Dlsite string `json:"dlsite"`
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
VideoQuality string `json:"videoquality"`
AcceptedTags Tags `json:"tags"`
UploaderID uint `json:"uploader_id"`
UploaderName template.HTML `json:"uploader_name"`
OldUploader template.HTML `json:"uploader_old"`
WebsiteLink template.URL `json:"website_link"`
Languages []string `json:"languages"`
Magnet template.URL `json:"magnet"`
TorrentLink template.URL `json:"torrent"`
Seeders uint32 `json:"seeders"`
Leechers uint32 `json:"leechers"`
Completed uint32 `json:"completed"`
LastScrape time.Time `json:"last_scrape"`
StatsObsolete []bool `json:"-"` //First cell determines whether the stats are valid, second determines whether the stats need a refresh regardless of first cell (too old stats?)
FileList []FileJSON `json:"file_list"`
Tags Tags `json:"-"` // not needed in json to reduce db calls
2017-05-10 10:27:17 +02:00
}
// Size : Returns the total size of memory recursively allocated for this struct
// FIXME: Is it deprecated?
func (t Torrent) Size() (s int) {
s = int(reflect.TypeOf(t).Size())
2017-05-10 10:27:17 +02:00
return
}
// TableName : Return the table name of torrents table
func (t Torrent) TableName() string {
return config.Get().Models.TorrentsTableName
}
// Identifier : Return the identifier of a torrent
2017-05-22 00:22:42 +02:00
func (t *Torrent) Identifier() string {
2017-07-09 16:21:34 +02:00
return fmt.Sprintf("torrent_%d", t.ID)
2017-05-20 20:53:05 +02:00
}
// IsNormal : Return if a torrent status is normal
func (t *Torrent) IsNormal() bool {
return t.Status == TorrentStatusNormal
}
// IsRemake : Return if a torrent status is remake
func (t *Torrent) IsRemake() bool {
return t.Status == TorrentStatusRemake
}
// IsTrusted : Return if a torrent status is trusted
func (t *Torrent) IsTrusted() bool {
return t.Status == TorrentStatusTrusted
}
// IsAPlus : Return if a torrent status is a+
func (t *Torrent) IsAPlus() bool {
return t.Status == TorrentStatusAPlus
}
// IsBlocked : Return if a torrent status is locked
Deleted torrents mod done (#732) * Torrent Mass Edit Api (WIP) * Torrents can be deleted in mass from frontend with api post request * Torrents status can be edited from frontend with api post request -- Look to function doc for more info on how to use it It is a WIP so it might not work =D * Finished Mass mod Api As per suggestion of @yiiTT in #720, I added: * Changing torrents category * Deletion of reports with deletion of a torrent * Changing owner of multiple torrents Commit also add some new translation strings. * Make some changes * Reports can now be cleared for the torrents selected without having to delete them * Users with no admin rights can't delete reports * Fix moveto to status moveto deprecated in api * Tested and works! Changes: * Updates only the colomns of torrent table * Moved categories config in config/torrents.go * Forgot this file in last commit * Less useless queries The use of Save makes it that users are created and updates also all the associatiated models. Better to just update the colomns needed (less useless queries) * Some Updates * Added a new status of 5 for locking torrents * Modifying the list torrents view for using it in deleted torrents view * Added function to get deleted torrents * Torrents (and reports) can be definitely deleted * Some new translation string * Fixing * fix 2 * Added upload check for locked torrents If a user owns a torrent, has deleted it and try to repload it. As long as it has not been locked, he can. * Fixing wrong condition in isdeleted * Finished * Info messages on success when deletes or lock * Fixed double deleted_at is Null * Added Link to view of deleted torrents * Added new translation string
2017-05-25 02:19:05 +02:00
func (t *Torrent) IsBlocked() bool {
return t.Status == TorrentStatusBlocked
}
// IsDeleted : Return if a torrent status is deleted
Deleted torrents mod done (#732) * Torrent Mass Edit Api (WIP) * Torrents can be deleted in mass from frontend with api post request * Torrents status can be edited from frontend with api post request -- Look to function doc for more info on how to use it It is a WIP so it might not work =D * Finished Mass mod Api As per suggestion of @yiiTT in #720, I added: * Changing torrents category * Deletion of reports with deletion of a torrent * Changing owner of multiple torrents Commit also add some new translation strings. * Make some changes * Reports can now be cleared for the torrents selected without having to delete them * Users with no admin rights can't delete reports * Fix moveto to status moveto deprecated in api * Tested and works! Changes: * Updates only the colomns of torrent table * Moved categories config in config/torrents.go * Forgot this file in last commit * Less useless queries The use of Save makes it that users are created and updates also all the associatiated models. Better to just update the colomns needed (less useless queries) * Some Updates * Added a new status of 5 for locking torrents * Modifying the list torrents view for using it in deleted torrents view * Added function to get deleted torrents * Torrents (and reports) can be definitely deleted * Some new translation string * Fixing * fix 2 * Added upload check for locked torrents If a user owns a torrent, has deleted it and try to repload it. As long as it has not been locked, he can. * Fixing wrong condition in isdeleted * Finished * Info messages on success when deletes or lock * Fixed double deleted_at is Null * Added Link to view of deleted torrents * Added new translation string
2017-05-25 02:19:05 +02:00
func (t *Torrent) IsDeleted() bool {
return t.DeletedAt != nil
}
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 09:21:07 +01:00
// IsAnon : Return if a torrent is displayed as anon
// Be aware, it doesn't mean that the owner is anonymous!
func (t *Torrent) IsAnon() bool {
return t.Hidden || t.UploaderID == 0
}
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
// GetDescriptiveTags : Return the descriptive tags
func (t *Torrent) GetDescriptiveTags() string {
return t.AcceptedTags
}
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 09:21:07 +01:00
// GetPath : Helpers to get the path to the torrent file
func (t *Torrent) GetPath() string {
return fmt.Sprintf("%s%c%s.torrent", config.Get().Torrents.FileStorage, os.PathSeparator, t.Hash)
}
// AddToESIndex : Adds a torrent to Elastic Search
func (t Torrent) AddToESIndex(client *elastic.Client) error {
ctx := context.Background()
torrentJSON := t.ToJSON()
_, err := client.Index().
Index(config.Get().Search.ElasticsearchIndex).
Type(config.Get().Search.ElasticsearchType).
Id(strconv.FormatUint(uint64(torrentJSON.ID), 10)).
BodyJson(torrentJSON).
Refresh("true").
Do(ctx)
return err
}
// DeleteFromESIndex : Removes a torrent from Elastic Search
func (t *Torrent) DeleteFromESIndex(client *elastic.Client) error {
ctx := context.Background()
_, err := client.Delete().
Index(config.Get().Search.ElasticsearchIndex).
Type(config.Get().Search.ElasticsearchType).
Id(strconv.FormatInt(int64(t.ID), 10)).
Do(ctx)
return err
}
// ParseTrackers : Takes an array of trackers, adds needed trackers and parse it to url string
func (t *Torrent) ParseTrackers(trackers []string) {
v := url.Values{}
if len(config.Get().Torrents.Trackers.NeededTrackers) > 0 { // if we have some needed trackers configured
if len(trackers) == 0 {
trackers = config.Get().Torrents.Trackers.Default
} else {
for _, id := range config.Get().Torrents.Trackers.NeededTrackers {
found := false
for _, tracker := range trackers {
if tracker == config.Get().Torrents.Trackers.Default[id] {
found = true
break
}
}
if !found {
trackers = append(trackers, config.Get().Torrents.Trackers.Default[id])
}
}
}
}
2017-10-29 04:38:33 +01:00
tempTrackers := []string{}
for _, line := range trackers {
if !contains(tempTrackers, line) {
tempTrackers = append(tempTrackers, line)
}
}
trackers = tempTrackers
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 09:21:07 +01:00
v["tr"] = trackers
t.Trackers = v.Encode()
}
func (t *Torrent) ParseLanguages() {
t.Languages = strings.Split(t.Language, ",")
}
func (t *Torrent) EncodeLanguages() {
t.Language = strings.Join(t.Languages, ",")
}
// GetTrackersArray : Convert trackers string to Array
func (t *Torrent) GetTrackersArray() (trackers []string) {
v, _ := url.ParseQuery(t.Trackers)
trackers = v["tr"]
return
}
// ToTorrent :
// TODO: Need to get rid of TorrentJSON altogether and have only one true Torrent
// model
func (t *TorrentJSON) ToTorrent() Torrent {
category, err := strconv.ParseInt(t.Category, 10, 64)
if err != nil {
category = 0
}
subCategory, err := strconv.ParseInt(t.SubCategory, 10, 64)
if err != nil {
subCategory = 0
}
// Need to add +00:00 at the end because ES doesn't store it by default
2017-06-26 17:10:53 +02:00
dateFixed := t.Date
if len(dateFixed) > 6 && dateFixed[len(dateFixed)-6] != '+' {
2017-06-26 17:10:53 +02:00
dateFixed += "Z"
}
date, err := time.Parse(time.RFC3339, dateFixed)
if err != nil {
2017-06-26 17:10:53 +02:00
log.Errorf("Problem parsing date '%s' from ES: %s", dateFixed, err)
}
torrent := Torrent{
ID: t.ID,
Name: t.Name,
Hash: t.Hash,
Category: int(category),
SubCategory: int(subCategory),
Status: t.Status,
Date: date,
UploaderID: t.UploaderID,
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
AnidbID: t.AnidbID,
VndbID: t.VndbID,
VgmdbID: t.VgmdbID,
Dlsite: t.Dlsite,
//Stardom: t.Stardom,
Filesize: t.Filesize,
Description: string(t.Description),
Hidden: t.Hidden,
//WebsiteLink: t.WebsiteLink,
//Trackers: t.Trackers,
//DeletedAt: t.DeletedAt,
// Uploader: TODO
//OldUploader: t.OldUploader,
//OldComments: TODO
// Comments: TODO
// LastScrape not stored in ES, counts won't show without a value however
Scrape: &Scrape{Seeders: t.Seeders, Leechers: t.Leechers, Completed: t.Completed, LastScrape: time.Now()},
Languages: t.Languages,
//FileList: TODO
}
torrent.EncodeLanguages()
return torrent
}
// ToJSON converts a models.Torrent to its equivalent JSON structure
func (t *Torrent) ToJSON() TorrentJSON {
var trackers []string
if t.Trackers == "" {
trackers = config.Get().Torrents.Trackers.Default
} else {
trackers = t.GetTrackersArray()
}
magnet := format.InfoHashToMagnet(strings.TrimSpace(t.Hash), t.Name, trackers...)
commentsJSON := make([]CommentJSON, 0, len(t.OldComments)+len(t.Comments))
2017-05-08 20:07:25 +02:00
for _, c := range t.OldComments {
commentsJSON = append(commentsJSON, CommentJSON{Username: c.Username, UserID: -1, UserStatus: "", Content: template.HTML(c.Content), Date: c.Date.UTC()})
2017-05-08 20:07:25 +02:00
}
for _, c := range t.Comments {
2017-05-17 07:58:40 +02:00
if c.User != nil {
Things (#1740) * Add new followers directly to user.Followers * Update user.go * Remove useless condition * Query an update of user followers if at 0 when looking at his profile * Fix comment not appearing until you refreshed the torrent page * call ViewHandler so that comments visually update properly * Remove now useless imports * Add "uploader" userstatus in comment * GetLikings() & GetFollowers() now return count too * Don't update follower count here * Update follower count directly here * show liking count * Update user.go * Update profile.jet.html * Update torrentParam.go * Fix locked torrents that were shown even when they should not * Update torrentParam_test.go * remove inline styling * Update main.css * Update upload.jet.html * Update main.css * Update tomorrow.css * Update classic.css * Update classic_colors.css * Update index_site.jet.html * Make announcements support markdown * Add markdown form to announcement creation * fix "report" text position * Add exclude search option to exclude words * Make sure the "NameLike" value is the search query because we edit it during a search * Show search content in page title for /feed too * rollback * Add "Search" variable that shows exactly what is being searched * Use "Search.Search" variable here instead of NameLike because NameLike is edited * Update torrentParam_test.go * Update torrentParam.go * remove redundant spaces from NameLike * Update torrentParam.go * Update torrentParam.go * Update torrentParam.go * Update torrentParam.go * turn date input into type date * bigger date inputs * add support for YYYY-MM-DD dates * rollback this change * rollback * Update search.jet.html * Update helpers.go * Update template_functions.go * Update torrentParam.go * only uploader & staff can comment on locked torrents * Add "Upload to Nyaa/Sukebei" button for mods * Update torrentlist.jet.html * Update view.jet.html * Update view.jet.html * fix wrong page title for notifications page
2017-11-20 02:13:00 +01:00
role := c.User.GetRole()
if t.UploaderID == c.User.ID && !c.User.IsBanned() {
role = "userstatus_uploader"
}
commentsJSON = append(commentsJSON, CommentJSON{Username: c.User.Username, UserID: int(c.User.ID), UserStatus: role, Content: sanitize.MarkdownToHTML(c.Content), Date: c.CreatedAt.UTC(), UserAvatar: c.User.MD5})
2017-05-17 00:05:16 +02:00
} else {
2017-05-17 07:58:40 +02:00
commentsJSON = append(commentsJSON, CommentJSON{})
2017-05-17 00:05:16 +02:00
}
2017-05-08 04:06:11 +02:00
}
// Sort comments by date
slice.Sort(commentsJSON, func(i, j int) bool {
return commentsJSON[i].Date.Before(commentsJSON[j].Date)
})
fileListJSON := make([]FileJSON, 0, len(t.FileList))
for _, f := range t.FileList {
fileListJSON = append(fileListJSON, FileJSON{
Path: filepath.Join(f.Path()...),
Filesize: f.Filesize,
})
}
// Sort file list by lowercase filename
slice.Sort(fileListJSON, func(i, j int) bool {
return strings.ToLower(fileListJSON[i].Path) < strings.ToLower(fileListJSON[j].Path)
})
uploader := "れんちょん" // by default
var uploaderID uint
if t.UploaderID > 0 && t.Uploader != nil {
uploader = t.Uploader.Username
uploaderID = t.UploaderID
} else if t.OldUploader != "" {
uploader = t.OldUploader
}
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 09:21:07 +01:00
scrape := Scrape{}
if t.Scrape != nil {
scrape = *t.Scrape
}
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 09:21:07 +01:00
statsObsolete := []bool{false, false}
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 09:21:07 +01:00
if scrape.LastScrape.IsZero() || (scrape.Seeders == 0 && scrape.Leechers == 0 && scrape.Completed == 0) {
statsObsolete[0] = true
//The displayed stats are obsolete, S/D/L will show "Unknown"
}
if time.Since(scrape.LastScrape).Hours() > config.Get().Scrape.StatScrapingFrequency || (scrape.Seeders == 0 && scrape.Leechers == 0 && scrape.Completed == 0 && time.Since(scrape.LastScrape).Hours() >= config.Get().Scrape.StatScrapingFrequencyUnknown) {
statsObsolete[1] = true
//The stats need to be refreshed, either because they are valid and older than one month (not that reliable) OR if they are unknown but have been scraped 1h (or more) ago
}
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 09:21:07 +01:00
t.ParseLanguages()
res := TorrentJSON{
ID: t.ID,
Name: t.Name,
Status: t.Status,
Hidden: t.Hidden,
Hash: t.Hash,
Date: t.Date.UTC().Format(time.RFC3339),
FullDate: t.Date.UTC(),
Filesize: t.Filesize,
Description: sanitize.MarkdownToHTML(t.Description),
Comments: commentsJSON,
SubCategory: strconv.Itoa(t.SubCategory),
Category: strconv.Itoa(t.Category),
UploaderID: uploaderID,
UploaderName: sanitize.SafeText(uploader),
WebsiteLink: sanitize.Safe(t.WebsiteLink),
Languages: t.Languages,
Magnet: template.URL(magnet),
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 09:21:07 +01:00
TorrentLink: sanitize.Safe(t.Download()),
Leechers: scrape.Leechers,
Seeders: scrape.Seeders,
Completed: scrape.Completed,
LastScrape: scrape.LastScrape,
StatsObsolete: statsObsolete,
FileList: fileListJSON,
Tags: t.Tags,
AnidbID: t.AnidbID,
VndbID: t.VndbID,
VgmdbID: t.VgmdbID,
Dlsite: t.Dlsite,
VideoQuality: t.VideoQuality,
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
}
// Split accepted tags
tags := strings.Split(t.AcceptedTags, ",")
for _, tag := range tags {
if tag != "" {
res.AcceptedTags = append(res.AcceptedTags, Tag{Tag: tag, Type: config.Get().Torrents.Tags.Default, Total: config.Get().Torrents.Tags.MaxWeight, Accepted: true})
}
2017-05-10 19:29:35 +02:00
}
return res
}
/* Complete the functions when necessary... */
2017-05-09 01:56:57 +02:00
// TorrentsToJSON : Map Torrents to TorrentsToJSON without reallocations
func TorrentsToJSON(t []Torrent) []TorrentJSON {
json := make([]TorrentJSON, len(t))
2017-05-09 01:56:57 +02:00
for i := range t {
json[i] = t[i].ToJSON()
2017-05-09 01:56:57 +02:00
}
return json
}
// Update : Update a torrent based on model
func (t *Torrent) Update(unscope bool) (int, error) {
db := ORM
if unscope {
db = ORM.Unscoped()
}
t.EncodeLanguages() // Need to transform array into single string
if db.Model(t).UpdateColumn(t.toMap()).Error != nil {
return http.StatusInternalServerError, errors.New("Torrent was not updated")
}
// TODO Don't create a new client for each request
if ElasticSearchClient != nil {
err := t.AddToESIndex(ElasticSearchClient)
if err == nil {
log.Infof("Successfully updated torrent to ES index.")
} else {
log.Errorf("Unable to update torrent to ES index: %s", err)
}
}
2017-07-28 20:43:22 +02:00
// We only flush cache after update
cache.C.Delete(t.Identifier())
return http.StatusOK, nil
}
// UpdateUnscope : Update a torrent based on model
func (t *Torrent) UpdateUnscope() (int, error) {
return t.Update(true)
}
2017-07-28 20:43:22 +02:00
// Delete : delete a torrent based on id
func (t *Torrent) Delete(definitely bool) (*Torrent, int, error) {
2017-07-30 03:29:09 +02:00
if t.ID == 0 {
err := errors.New("ERROR: Tried to delete a torrent with ID 0")
log.CheckErrorWithMessage(err, "ERROR_IMPORTANT: ")
return t, http.StatusBadRequest, err
}
db := ORM
if definitely {
db = ORM.Unscoped()
}
if db.Delete(t).Error != nil {
return t, http.StatusInternalServerError, errors.New("torrent_not_deleted")
}
if ElasticSearchClient != nil {
err := t.DeleteFromESIndex(ElasticSearchClient)
if err == nil {
log.Infof("Successfully deleted torrent to ES index.")
} else {
log.Errorf("Unable to delete torrent to ES index: %s", err)
}
}
2017-07-28 20:43:22 +02:00
// We flush cache only after delete
cache.C.Flush()
return t, http.StatusOK, nil
}
// DefinitelyDelete : deletes definitely a torrent based on id
func (t *Torrent) DefinitelyDelete() (*Torrent, int, error) {
return t.Delete(true)
}
// toMap : convert the model to a map of interface
func (t *Torrent) toMap() map[string]interface{} {
return structs.Map(t)
}
2017-07-28 20:43:22 +02:00
// LoadTags : load all the unique tags with summed up weight from the database in torrent
func (t *Torrent) LoadTags() {
// Only load if necessary
if len(t.Tags) == 0 {
// Should output a query like this: SELECT tag, type, accepted, SUM(weight) as total FROM tags WHERE torrent_id=923000 GROUP BY type, tag ORDER BY type, total DESC
Tag Search + Tests + Search slight refactor [DONE] (#1342) * Tag Search + Tests + Search slight refactor First commit improving search. Different struct have their own file with their tests. This way of separating struct by files is inspired by the go packages I've seen so far. Added new behaviour as discussed in #1334 * fix fallback to ES * Added some comments to explain PG fallback + log err moved * Refactored search Nearly fully covered WhereParams struct has disappeared for Query struct instead In DB model, we use an interface implementing Query struct methods * 1rst Refactor of Tags (WTF already?!) Prepare Tags for the refactored system. Now there will be descriptive tags for a particular release (ecchi, BDSM, ....) and typed tags. Typed tags are tags relevant to all torrents and can be limited to some input value. For example, video quality is a typed tag limited to some values (hd, full hd, sd, ...). In the same way, anidbid is also a typed tag but doesn't have default values. Furthermore, the location storage of tags have changed, now accepted descriptive tags are stored in the torrents table in the column "tags" and they are separated by commas. In the opposite, accepted typed tags can have have their own column in the torrents table. For example, anidbid, vndbid will populate the column DbID when accepted. On the other hand, videoquality will populate the same way as descriptive tags. This behaviour depends on the callbackOnType function in tag/helpers.go * fix for modtools :') * Added anidb, vndb, dlsite & vmdb id fields in torrent model. Tags don't have an accepted field anymore. Accepted Tags are in torrent.AcceptedTags and non-accepted ones in torrrent.Tags. New Helper + New Changelog for translation string. * New upload/edit form for torrent tags. Now the inputs are dynamically generated by the helper tag_form. No more modal window in those form, only inputs. Support of tags in API New translation string for the link to the modal on torrent view. More comments in the functions for tags * Improving how config for tags work. Adding a test on them with understandable messages. Config for tags have now a Field attribute which is linked to the Torrent model. For example anidbid tag type has now a AnidbID field in config which is the name of the field in torrent model (AnidbID). Every new tag type need to have a field attribute with its counterpart in torrent Model. Fixing some errors * Fix compile error + Tests Errors * Improve performance by caching the list of tags with an index Adding/removing tags works/tested New translation strings TODO: test/fix adding tag on upload/edit * Mini fix to display video quality + tags works/tested on modo edit * Fix editing tags on modpanel * Edit tags works * Add translation string * Add search backend for tags. ?tags=xxx,eee,ddd ?anidb=21 ?vndb=23 ?vgmdb=24 ?vq=full_hd * Fix Ajax tag Removal&Add * Added form for descriptive tags * Forgot to add the link between database and form for descriptive tags. * Adding the increase/decrease pantsu for descriptive tags * Fix #1370 * When you actually forgot to commit files after having forgotten commits
2017-08-22 03:48:10 +02:00
err := ORM.Select("tag, type, SUM(weight) as total").Where("torrent_id = ?", t.ID).Group("type, tag").Order("type ASC, total DESC").Find(&t.Tags).Error
log.CheckErrorWithMessage(err, "LOAD_TAGS_ERROR: Couldn't load tags from DB!")
2017-07-28 20:43:22 +02:00
}
}
// DeleteTags cipes out all the tags from the torrent. Doesn't decrease pantsu on users!
func (t *Torrent) DeleteTags() {
if t.ID > 0 {
// Should output a query like this: DELETE FROM tags WHERE torrent_id=923000
err := ORM.Where("torrent_id = ?", t.ID).Delete(&t.Tags).Error
log.CheckErrorWithMessage(err, "LOAD_TAGS_ERROR: Couldn't delete tags!")
}
}
2017-10-29 04:38:33 +01:00
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 09:21:07 +01:00
// Download generate a download link for a torrent
func (t *Torrent) Download() (torrentlink string) {
if len(config.Get().Torrents.CacheLink) > 0 { // Only use torrent cache if set, don't check id since better to have all .torrent
if !config.IsSukebei() { // torrent cache doesn't have sukebei torrents
torrentlink = fmt.Sprintf(config.Get().Torrents.CacheLink, t.Hash)
}
return
}
if len(config.Get().Torrents.StorageLink) > 0 { // Only use own .torrent if storage set
torrentlink = fmt.Sprintf(config.Get().Torrents.StorageLink, t.Hash)
}
return
}
2017-10-29 04:38:33 +01:00
func contains(s []string, e string) bool {
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 09:21:07 +01:00
for _, a := range s {
if a == e {
return true
}
}
return false
2017-10-29 04:38:33 +01:00
}