Adding upload of multi lang full support
Cette révision appartient à :
Parent
1796538c36
révision
330ab06597
10 fichiers modifiés avec 26 ajouts et 4 suppressions
|
@ -382,7 +382,7 @@ func TorrentsPostListPanel(c *gin.Context) {
|
|||
* Needed: torrent_id[] Ids of torrents in checkboxes of name torrent_id
|
||||
*
|
||||
* Needed on context:
|
||||
* status=0|1|2|3|4 according to config/torrent.go (can be omitted if action=delete|owner|category|multiple)
|
||||
* status=0|1|2|3|4 according to config/find.go (can be omitted if action=delete|owner|category|multiple)
|
||||
* owner is the User ID of the new owner of the torrents (can be omitted if action=delete|status|category|multiple)
|
||||
* category is the category string (eg. 1_3) of the new category of the torrents (can be omitted if action=delete|status|owner|multiple)
|
||||
*
|
||||
|
|
|
@ -281,5 +281,13 @@ func templateFunctions(vars jet.VarMap) jet.VarMap {
|
|||
vars.Set("genActivityContent", func(a models.Activity, T publicSettings.TemplateTfunc) template.HTML {
|
||||
return a.ToLocale(T)
|
||||
})
|
||||
vars.Set("contains", func(arr []string, comp string) bool {
|
||||
for _, str := range arr {
|
||||
if str == comp {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
})
|
||||
return vars
|
||||
}
|
||||
|
|
|
@ -367,6 +367,7 @@ func (t *Torrent) Update(unscope bool) (int, error) {
|
|||
if unscope {
|
||||
db = ORM.Unscoped()
|
||||
}
|
||||
t.EncodeLanguages() // Need to transform array into single string
|
||||
if db.Model(t).UpdateColumn(t).Error != nil {
|
||||
return http.StatusInternalServerError, errors.New("Torrent was not updated")
|
||||
}
|
||||
|
|
|
@ -18,9 +18,11 @@ func Create(user *models.User, uploadForm *torrentValidator.TorrentRequest) (*mo
|
|||
Hash: uploadForm.Infohash,
|
||||
Date: time.Now(),
|
||||
Filesize: uploadForm.Filesize,
|
||||
Languages: uploadForm.Languages,
|
||||
Description: uploadForm.Description,
|
||||
WebsiteLink: uploadForm.WebsiteLink,
|
||||
UploaderID: user.ID}
|
||||
torrent.EncodeLanguages() // Convert languages array in language string
|
||||
torrent.ParseTrackers(uploadForm.Trackers)
|
||||
models.ORM.Create(&torrent)
|
||||
if models.ElasticSearchClient != nil {
|
||||
|
|
|
@ -36,6 +36,7 @@ func FindByID(id uint) (torrent models.Torrent, err error) {
|
|||
err = errors.New("Article is not found")
|
||||
return
|
||||
}
|
||||
torrent.ParseLanguages()
|
||||
// GORM relly likes not doing its job correctly
|
||||
// (or maybe I'm just retarded)
|
||||
torrent.Uploader = new(models.User)
|
||||
|
@ -65,6 +66,7 @@ func FindRawByID(id uint) (torrent models.Torrent, err error) {
|
|||
if models.ORM.Where("torrent_id = ?", id).Find(&torrent).RecordNotFound() {
|
||||
err = errors.New("Torrent is not found")
|
||||
}
|
||||
torrent.ParseLanguages()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -75,6 +77,7 @@ func FindRawByHash(hash string) (torrent models.Torrent, err error) {
|
|||
if models.ORM.Where("torrent_hash = ?", hash).Find(&torrent).RecordNotFound() {
|
||||
err = errors.New("Torrent is not found")
|
||||
}
|
||||
torrent.ParseLanguages()
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -180,6 +183,7 @@ func ToggleBlock(id uint) (models.Torrent, int, error) {
|
|||
if models.ORM.Unscoped().Model(&torrent).First(&torrent, id).RecordNotFound() {
|
||||
return torrent, http.StatusNotFound, errors.New("Torrent is not found")
|
||||
}
|
||||
torrent.ParseLanguages()
|
||||
if torrent.Status == models.TorrentStatusBlocked {
|
||||
torrent.Status = models.TorrentStatusNormal
|
||||
} else {
|
|
@ -24,7 +24,7 @@
|
|||
<label for="language">{{ T("torrent_language") }}</label>
|
||||
<div name="language" class="form-input language">
|
||||
{{ range _, language := GetTorrentLanguages() }}
|
||||
<input type="checkbox" name="lang-{{ language }}" id="lang-{{ language }}">
|
||||
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}"{{if contains(.Languages, language) }} checked{{end}}>
|
||||
<label for="lang-{{ language }}" class="flag flag-{{ FlagCode(language) }}" title="{{LanguageName(language, T)}}"></label>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
<label class="input-label" for="language">{{ T("torrent_language") }}</label>
|
||||
<div name="language" class="form-input language">
|
||||
{{ range _, language := GetTorrentLanguages() }}
|
||||
<input type="checkbox" name="lang-{{ language }}" id="lang-{{ language }}">
|
||||
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}"{{if contains(.Languages, language) }} checked{{end}}>
|
||||
<label for="lang-{{ language }}" class="flag flag-{{ FlagCode(language) }}" title="{{LanguageName(language, T)}}"></label>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
<h3>{{ T("torrent_language") }}</h3>
|
||||
<div name="language" class="form-input language">
|
||||
{{ range _, language := GetTorrentLanguages() }}
|
||||
<input type="checkbox" name="lang-{{ language }}" id="lang-{{ language }}">
|
||||
<input type="checkbox" name="languages" id="lang-{{ language }}" value="{{language}}">
|
||||
<label for="lang-{{ language }}" class="flag flag-{{ FlagCode(language) }}" title="{{LanguageName(language, T)}}"></label>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
|
|
@ -3,6 +3,8 @@ package torrentLanguages
|
|||
import (
|
||||
"strings"
|
||||
|
||||
"sort"
|
||||
|
||||
"github.com/NyaaPantsu/nyaa/config"
|
||||
"github.com/NyaaPantsu/nyaa/utils/publicSettings"
|
||||
)
|
||||
|
@ -17,6 +19,7 @@ func initTorrentLanguages() {
|
|||
|
||||
// Also support languages we don't have a translation
|
||||
torrentLanguages = append(torrentLanguages, config.Conf.Torrents.AdditionalLanguages...)
|
||||
sort.Strings(torrentLanguages)
|
||||
}
|
||||
|
||||
// GetTorrentLanguages returns a list of available torrent languages.
|
||||
|
|
|
@ -92,7 +92,11 @@ func ExtractBasicValue(c *gin.Context, r *torrentValidator.TorrentRequest) error
|
|||
r.WebsiteLink = strings.TrimSpace(r.WebsiteLink)
|
||||
r.Magnet = strings.TrimSpace(r.Magnet)
|
||||
|
||||
fmt.Println("Languages:")
|
||||
fmt.Println(r.Languages)
|
||||
r.Languages = c.PostFormArray("languages")
|
||||
// then actually check that we have everything we need
|
||||
fmt.Println(r.Languages)
|
||||
|
||||
err := r.ValidateDescription()
|
||||
if err != nil {
|
||||
|
|
Référencer dans un nouveau ticket