Change DLSite to String (#1576)
* Change DLSite to String Fix #1573 Plus it seems the filtering search for ES didn't work for anidbid, vndbid and vgmdb. Should be fixed now. * Update helpers.go
Cette révision appartient à :
Parent
cedbec3246
révision
421935f8be
|
@ -3,6 +3,7 @@ package tags
|
|||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -123,11 +124,21 @@ func callbackOnType(tag *models.Tag, torrent *models.Torrent) {
|
|||
}
|
||||
// We finally add the tag to the column
|
||||
torrent.AcceptedTags += tag.Tag
|
||||
case "anidbid", "vndbid", "vgmdbid", "dlsite":
|
||||
case "anidbid", "vndbid", "vgmdbid":
|
||||
u64, _ := strconv.ParseUint(tag.Tag, 10, 32)
|
||||
// TODO: Perform a check that anidbid is in anidb database
|
||||
tagConf := config.Get().Torrents.Tags.Types.Get(tag.Type)
|
||||
reflect.ValueOf(torrent).Elem().FieldByName(tagConf.Field).SetUint(u64)
|
||||
case "dlsite":
|
||||
// Since DLSite has a particular format, we don't use the default behavior but we check the format
|
||||
tagConf := config.Get().Torrents.Tags.Types.Get(tag.Type)
|
||||
if len(tag.Tag) != 8 { // eg RJ001001
|
||||
return
|
||||
}
|
||||
var validID = regexp.MustCompile(`^[A-Za-z]{2}[0-9]{6}$`)
|
||||
if validID.MatchString(tag.Tag) {
|
||||
reflect.ValueOf(torrent).Elem().FieldByName(tagConf.Field).SetString(tag.Tag)
|
||||
}
|
||||
default:
|
||||
// Some tag type can have default values that you have to choose from
|
||||
// We, here, check that the tag is one of them
|
||||
|
|
|
@ -59,7 +59,7 @@ type Torrent struct {
|
|||
AnidbID uint `gorm:"column:anidbid"`
|
||||
VndbID uint `gorm:"column:vndbid"`
|
||||
VgmdbID uint `gorm:"column:vgmdbid"`
|
||||
Dlsite uint `gorm:"column:dlsite"`
|
||||
Dlsite string `gorm:"column:dlsite"`
|
||||
VideoQuality string `gorm:"column:videoquality"`
|
||||
AcceptedTags string `gorm:"column:tags"`
|
||||
// Indicates the language of the torrent's content (eg. subs, dubs, raws, manga TLs)
|
||||
|
@ -97,7 +97,7 @@ type TorrentJSON struct {
|
|||
AnidbID uint `json:"anidbid"`
|
||||
VndbID uint `json:"vndbid"`
|
||||
VgmdbID uint `json:"vgmdbid"`
|
||||
Dlsite uint `json:"dlsite"`
|
||||
Dlsite string `json:"dlsite"`
|
||||
VideoQuality string `json:"videoquality"`
|
||||
AcceptedTags Tags `json:"tags"`
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
{{ if Torrent.AnidbID > 0 || Torrent.VndbID > 0 || Torrent.VgmdbID > 0 || Torrent.Dlsite > 0 }}
|
||||
{{ if Torrent.AnidbID > 0 || Torrent.VndbID > 0 || Torrent.VgmdbID > 0 || Torrent.Dlsite != "" }}
|
||||
<tr class="torrent-info-row">
|
||||
<td class="torrent-info-td torrent-info-label">{{ T("related_to") }}</td>
|
||||
<td class="tr-flag torrent-view-td torrent-info-data">
|
||||
|
@ -89,7 +89,7 @@
|
|||
<a href="/search?vgm={{ Torrent.VgmdbID }}" title="{{ T("filter") }}"><i class="icon-search"></i></a>
|
||||
</span>
|
||||
{{end}}
|
||||
{{ if Torrent.Dlsite > 0 }}
|
||||
{{ if Torrent.Dlsite != "" }}
|
||||
<span class="tag accepted">
|
||||
<span class="tag-text votable"><a href="http://www.dlsite.com/home/work/=/product_id/{{ Torrent.Dlsite }}.html">{{ T("tagtype_dlsite") }}: {{ Torrent.Dlsite }}</a></span>
|
||||
<a href="/search?dlsite={{ Torrent.Dlsite }}" title="{{ T("filter") }}"><i class="icon-search"></i></a>
|
||||
|
|
|
@ -56,7 +56,7 @@ func walkDirTest(dir string, t *testing.T) {
|
|||
fakeScrapeData := &models.Scrape{1, 0, 0, 10, time.Now()}
|
||||
fakeFile := &models.File{1, 1, "l12:somefile.mp4e", 3}
|
||||
fakeLanguages := []string{"fr", "en"}
|
||||
fakeTorrent := &models.Torrent{1, "test", "test", 3, 12, 1, false, time.Now(), 1, 0, 3, "test", "test", "test", 12, 12, 12, 12, "", "", "", nil, fakeUser, "test", []models.OldComment{}, []models.Comment{*fakeComment, *fakeComment}, []models.Tag{*fakeTag, *fakeTag}, fakeScrapeData, []models.File{*fakeFile}, fakeLanguages}
|
||||
fakeTorrent := &models.Torrent{1, "test", "test", 3, 12, 1, false, time.Now(), 1, 0, 3, "test", "test", "test", 12, 12, 12, "RJ001001", "", "", "", nil, fakeUser, "test", []models.OldComment{}, []models.Comment{*fakeComment, *fakeComment}, []models.Tag{*fakeTag, *fakeTag}, fakeScrapeData, []models.File{*fakeFile}, fakeLanguages}
|
||||
fakeActivity := &models.Activity{1, "t", "e", "s", 1, fakeUser}
|
||||
fakeDB := &models.DatabaseDump{time.Now(), 3, "test", "test"}
|
||||
fakeLanguage := &publicSettings.Language{"English", "en", "en-us"}
|
||||
|
|
|
@ -45,7 +45,7 @@ type TorrentParam struct {
|
|||
AnidbID uint32
|
||||
VndbID uint32
|
||||
VgmdbID uint32
|
||||
Dlsite uint32
|
||||
Dlsite string
|
||||
VideoQuality string
|
||||
Tags Tags
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ func (p *TorrentParam) Identifier() string {
|
|||
// Tags identifier
|
||||
tags := strings.Join(p.Tags, ",")
|
||||
tags += p.VideoQuality
|
||||
dbids := fmt.Sprintf("%d%d%d%d", p.AnidbID, p.VndbID, p.VgmdbID, p.Dlsite)
|
||||
dbids := fmt.Sprintf("%d%d%d%s", p.AnidbID, p.VndbID, p.VgmdbID, p.Dlsite)
|
||||
|
||||
identifier := fmt.Sprintf("%s%s%s%d%d%d%d%d%d%d%s%s%s%d%s%s%s%t%t%t%t", p.NameLike, p.NotNull, languages, p.Max, p.Offset, p.FromID, p.MinSize, p.MaxSize, p.Status, p.Sort, dbids, p.FromDate, p.ToDate, p.UserID, ids, cats, tags, p.Full, p.Order, p.Hidden, p.Deleted)
|
||||
return base64.URLEncoding.EncodeToString([]byte(identifier))
|
||||
|
@ -149,7 +149,7 @@ func (p *TorrentParam) FromRequest(c *gin.Context) {
|
|||
p.AnidbID = parseUInt(c, "anidb")
|
||||
p.VndbID = parseUInt(c, "vndb")
|
||||
p.VgmdbID = parseUInt(c, "vgm")
|
||||
p.Dlsite = parseUInt(c, "dlsite")
|
||||
p.Dlsite = c.Query("dlsite")
|
||||
|
||||
// Limit search to video quality
|
||||
// Get the video quality from url
|
||||
|
@ -274,19 +274,19 @@ func (p *TorrentParam) toESQuery(c *gin.Context) *Query {
|
|||
// Tags search
|
||||
// Anidb
|
||||
if p.AnidbID != 0 {
|
||||
query.Append("anidbid:" + strconv.FormatInt(int64(p.FromID), 10))
|
||||
query.Append("anidbid:" + strconv.FormatInt(int64(p.AnidbID), 10))
|
||||
}
|
||||
// Vndb
|
||||
if p.VndbID != 0 {
|
||||
query.Append("vndbid:" + strconv.FormatInt(int64(p.FromID), 10))
|
||||
query.Append("vndbid:" + strconv.FormatInt(int64(p.VndbID), 10))
|
||||
}
|
||||
// Vgmdb
|
||||
if p.VgmdbID != 0 {
|
||||
query.Append("vgmdbid:" + strconv.FormatInt(int64(p.FromID), 10))
|
||||
query.Append("vgmdbid:" + strconv.FormatInt(int64(p.VgmdbID), 10))
|
||||
}
|
||||
// Dlsite
|
||||
if p.Dlsite != 0 {
|
||||
query.Append("dlsite:" + strconv.FormatInt(int64(p.FromID), 10))
|
||||
if p.Dlsite != "" {
|
||||
query.Append("dlsite:" + p.Dlsite)
|
||||
}
|
||||
// Video quality
|
||||
if p.VideoQuality != "" {
|
||||
|
@ -427,7 +427,7 @@ func (p *TorrentParam) toDBQuery(c *gin.Context) *Query {
|
|||
query.Append("vgmdbid = ?", p.VgmdbID)
|
||||
}
|
||||
// Dlsite
|
||||
if p.Dlsite > 0 {
|
||||
if p.Dlsite != "" {
|
||||
query.Append("dlsite = ?", p.Dlsite)
|
||||
}
|
||||
// Video quality
|
||||
|
|
|
@ -12,13 +12,13 @@ import (
|
|||
func TestTorrentParam_Identifier(t *testing.T) {
|
||||
torrentParam := &TorrentParam{}
|
||||
assert := assert.New(t)
|
||||
assert.Equal("MDAwMDAwMDAwMDAwZmFsc2VmYWxzZWZhbHNlZmFsc2U=", torrentParam.Identifier(), "It should be empty")
|
||||
assert.Equal("MDAwMDAwMDAwMDBmYWxzZWZhbHNlZmFsc2VmYWxzZQ==", torrentParam.Identifier(), "It should be empty")
|
||||
torrentParam = &TorrentParam{
|
||||
NameLike: "test",
|
||||
NotNull: "IS NULL",
|
||||
Hidden: false,
|
||||
}
|
||||
assert.Equal("dGVzdElTIE5VTEwwMDAwMDAwMDAwMDBmYWxzZWZhbHNlZmFsc2VmYWxzZQ==", torrentParam.Identifier(), "It should be empty")
|
||||
assert.Equal("dGVzdElTIE5VTEwwMDAwMDAwMDAwMGZhbHNlZmFsc2VmYWxzZWZhbHNl", torrentParam.Identifier(), "It should be empty")
|
||||
}
|
||||
|
||||
func TestTorrentParam_FromRequest(t *testing.T) {
|
||||
|
|
|
@ -207,7 +207,7 @@ func TestTagsRequest_Bind(t *testing.T) {
|
|||
{&models.Torrent{}, nil, nil},
|
||||
{&models.Torrent{AnidbID: 1}, TagsRequest{tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}}, nil},
|
||||
{&models.Torrent{AnidbID: 1, VndbID: 2}, TagsRequest{tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "2", Type: "vndbid"}}, nil},
|
||||
{&models.Torrent{AnidbID: 1, VndbID: 2, VgmdbID: 3, Dlsite: 4, AcceptedTags: "ddd,ddd,ddd", VideoQuality: "full_hd"}, TagsRequest{tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "2", Type: "vndbid"}, tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "2", Type: "vndbid"}, tagsValidator.CreateForm{Tag: "4", Type: "dlsite"}, tagsValidator.CreateForm{Tag: "3", Type: "vgmdbid"}, tagsValidator.CreateForm{Tag: "full_hd", Type: "videoquality"}, tagsValidator.CreateForm{Tag: "ddd,ddd,ddd", Type: "tags"}}, nil},
|
||||
{&models.Torrent{AnidbID: 1, VndbID: 2, VgmdbID: 3, Dlsite: "RJ001001", AcceptedTags: "ddd,ddd,ddd", VideoQuality: "full_hd"}, TagsRequest{tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "2", Type: "vndbid"}, tagsValidator.CreateForm{Tag: "1", Type: "anidbid"}, tagsValidator.CreateForm{Tag: "2", Type: "vndbid"}, tagsValidator.CreateForm{Tag: "RJ001001", Type: "dlsite"}, tagsValidator.CreateForm{Tag: "3", Type: "vgmdbid"}, tagsValidator.CreateForm{Tag: "full_hd", Type: "videoquality"}, tagsValidator.CreateForm{Tag: "ddd,ddd,ddd", Type: "tags"}}, nil},
|
||||
}
|
||||
for _, test := range tests {
|
||||
err := r.Tags.Bind(test.Test)
|
||||
|
|
Référencer dans un nouveau ticket