Final work to add torrents categories

This commit is contained in:
LIAUD Corentin
2024-03-24 16:10:49 +01:00
parent 28e24de557
commit a7417a221a
11 changed files with 73 additions and 60 deletions

2
.gitignore vendored
View File

@@ -41,3 +41,5 @@ server/config.db
server/web/pages/template/route.go
server/server.pem
server/server.key
settings.json
viewed.json

View File

@@ -114,7 +114,7 @@ func GetTorrent(hashHex string) *Torrent {
return tor
}
func SetTorrent(hashHex, title, poster, data string) *Torrent {
func SetTorrent(hashHex, title, poster, category string, data string) *Torrent {
hash := metainfo.NewHashFromHex(hashHex)
torr := bts.GetTorrent(hash)
torrDb := GetTorrentDB(hash)
@@ -133,12 +133,14 @@ func SetTorrent(hashHex, title, poster, data string) *Torrent {
}
torr.Title = title
torr.Poster = poster
torr.Category = category
torr.Data = data
}
if torrDb != nil {
torrDb.Title = title
torrDb.Poster = poster
torrDb.Category = category
torrDb.Data = data
AddTorrentDB(torrDb)
}

View File

@@ -75,6 +75,7 @@ func ListTorrentsDB() map[metainfo.Hash]*Torrent {
torr.Poster = db.Poster
torr.Timestamp = db.Timestamp
torr.Size = db.Size
torr.Category = db.Category
torr.Data = db.Data
torr.Stat = state.TorrentInDB
ret[torr.TorrentSpec.InfoHash] = torr

View File

@@ -153,7 +153,7 @@ func setTorrent(req torrReqJS, c *gin.Context) {
c.AbortWithError(http.StatusBadRequest, errors.New("hash is empty"))
return
}
torr.SetTorrent(req.Hash, req.Title, req.Poster, req.Data)
torr.SetTorrent(req.Hash, req.Title, req.Poster, req.Category, req.Data)
c.Status(200)
}

View File

@@ -118,20 +118,20 @@ var Mstile150x150png []byte
//go:embed pages/site.webmanifest
var Sitewebmanifest []byte
//go:embed pages/static/js/2.916c2545.chunk.js
var Staticjs2916c2545chunkjs []byte
//go:embed pages/static/js/2.00261e25.chunk.js
var Staticjs200261e25chunkjs []byte
//go:embed pages/static/js/2.916c2545.chunk.js.LICENSE.txt
var Staticjs2916c2545chunkjsLICENSEtxt []byte
//go:embed pages/static/js/2.00261e25.chunk.js.LICENSE.txt
var Staticjs200261e25chunkjsLICENSEtxt []byte
//go:embed pages/static/js/2.916c2545.chunk.js.map
var Staticjs2916c2545chunkjsmap []byte
//go:embed pages/static/js/2.00261e25.chunk.js.map
var Staticjs200261e25chunkjsmap []byte
//go:embed pages/static/js/main.55f380e1.chunk.js
var Staticjsmain55f380e1chunkjs []byte
//go:embed pages/static/js/main.4f4f0915.chunk.js
var Staticjsmain4f4f0915chunkjs []byte
//go:embed pages/static/js/main.55f380e1.chunk.js.map
var Staticjsmain55f380e1chunkjsmap []byte
//go:embed pages/static/js/main.4f4f0915.chunk.js.map
var Staticjsmain4f4f0915chunkjsmap []byte
//go:embed pages/static/js/runtime-main.f542387e.js
var Staticjsruntimemainf542387ejs []byte

View File

@@ -1,17 +1,17 @@
{
"files": {
"main.js": "/static/js/main.55f380e1.chunk.js",
"main.js.map": "/static/js/main.55f380e1.chunk.js.map",
"main.js": "/static/js/main.4f4f0915.chunk.js",
"main.js.map": "/static/js/main.4f4f0915.chunk.js.map",
"runtime-main.js": "/static/js/runtime-main.f542387e.js",
"runtime-main.js.map": "/static/js/runtime-main.f542387e.js.map",
"static/js/2.916c2545.chunk.js": "/static/js/2.916c2545.chunk.js",
"static/js/2.916c2545.chunk.js.map": "/static/js/2.916c2545.chunk.js.map",
"static/js/2.00261e25.chunk.js": "/static/js/2.00261e25.chunk.js",
"static/js/2.00261e25.chunk.js.map": "/static/js/2.00261e25.chunk.js.map",
"index.html": "/index.html",
"static/js/2.916c2545.chunk.js.LICENSE.txt": "/static/js/2.916c2545.chunk.js.LICENSE.txt"
"static/js/2.00261e25.chunk.js.LICENSE.txt": "/static/js/2.00261e25.chunk.js.LICENSE.txt"
},
"entrypoints": [
"static/js/runtime-main.f542387e.js",
"static/js/2.916c2545.chunk.js",
"static/js/main.55f380e1.chunk.js"
"static/js/2.00261e25.chunk.js",
"static/js/main.4f4f0915.chunk.js"
]
}

File diff suppressed because one or more lines are too long

View File

@@ -207,7 +207,7 @@ func RouteWebPages(route gin.IRouter) {
etag := fmt.Sprintf("%x", md5.Sum(Browserconfigxml))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/xml; charset=utf-8", Browserconfigxml)
c.Data(200, "text/xml; charset=utf-8", Browserconfigxml)
})
route.GET("/dlnaicon-120.png", func(c *gin.Context) {
@@ -280,46 +280,46 @@ func RouteWebPages(route gin.IRouter) {
c.Data(200, "application/manifest+json", Sitewebmanifest)
})
route.GET("/static/js/2.916c2545.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2916c2545chunkjs))
route.GET("/static/js/2.00261e25.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs200261e25chunkjs))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/javascript; charset=utf-8", Staticjs2916c2545chunkjs)
c.Data(200, "text/javascript; charset=utf-8", Staticjs200261e25chunkjs)
})
route.GET("/static/js/2.916c2545.chunk.js.LICENSE.txt", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2916c2545chunkjsLICENSEtxt))
route.GET("/static/js/2.00261e25.chunk.js.LICENSE.txt", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs200261e25chunkjsLICENSEtxt))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "text/plain; charset=utf-8", Staticjs2916c2545chunkjsLICENSEtxt)
c.Data(200, "text/plain; charset=utf-8", Staticjs200261e25chunkjsLICENSEtxt)
})
route.GET("/static/js/2.916c2545.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs2916c2545chunkjsmap))
route.GET("/static/js/2.00261e25.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjs200261e25chunkjsmap))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/json", Staticjs2916c2545chunkjsmap)
c.Data(200, "application/json", Staticjs200261e25chunkjsmap)
})
route.GET("/static/js/main.55f380e1.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain55f380e1chunkjs))
route.GET("/static/js/main.4f4f0915.chunk.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain4f4f0915chunkjs))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/javascript; charset=utf-8", Staticjsmain55f380e1chunkjs)
c.Data(200, "text/javascript; charset=utf-8", Staticjsmain4f4f0915chunkjs)
})
route.GET("/static/js/main.55f380e1.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain55f380e1chunkjsmap))
route.GET("/static/js/main.4f4f0915.chunk.js.map", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsmain4f4f0915chunkjsmap))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/json", Staticjsmain55f380e1chunkjsmap)
c.Data(200, "application/json", Staticjsmain4f4f0915chunkjsmap)
})
route.GET("/static/js/runtime-main.f542387e.js", func(c *gin.Context) {
etag := fmt.Sprintf("%x", md5.Sum(Staticjsruntimemainf542387ejs))
c.Header("Cache-Control", "public, max-age=31536000")
c.Header("ETag", etag)
c.Data(200, "application/javascript; charset=utf-8", Staticjsruntimemainf542387ejs)
c.Data(200, "text/javascript; charset=utf-8", Staticjsruntimemainf542387ejs)
})
route.GET("/static/js/runtime-main.f542387e.js.map", func(c *gin.Context) {

View File

@@ -26,12 +26,13 @@ export default function AddDialog({
title: originalTitle,
name: originalName,
poster: originalPoster,
category: originalCategory,
}) {
const { t } = useTranslation()
const isEditMode = !!originalHash
const [torrentSource, setTorrentSource] = useState(originalHash || '')
const [title, setTitle] = useState(originalTitle || '')
const [category, setCategory] = useState('Unknown')
const [category, setCategory] = useState(originalCategory || '')
const [originalTorrentTitle, setOriginalTorrentTitle] = useState('')
const [parsedTitle, setParsedTitle] = useState('')
const [posterUrl, setPosterUrl] = useState(originalPoster || '')
@@ -248,7 +249,6 @@ export default function AddDialog({
setTorrentSource={setTorrentSource}
/>
)}
<RightSideComponent
originalTorrentTitle={originalTorrentTitle}
setTitle={setTitle}

View File

@@ -69,6 +69,8 @@ export default function RightSideComponent({
setIsUserInteractedWithPoster(true)
}
const torrentCategories = ['Movies', 'Series', 'Music', 'Other', 'Unknown']
return (
<RightSide>
<RightSideContainer isHidden={!isTorrentSourceCorrect || (isHashAlreadyExists && !isEditMode)}>
@@ -113,26 +115,6 @@ export default function RightSideComponent({
),
}}
/>
<FormControl fullWidth>
<InputLabel id='torrent-category-select-label'>Torrent category</InputLabel>
<Select
labelId='torrent-category-select-label'
id='torrent-category-select'
value={category}
label='Torrent category'
margin='dense'
onChange={handleCategoryChange}
variant='outlined'
fullWidth
>
<MenuItem value='Films'>Films</MenuItem>
<MenuItem value='Series'>Series</MenuItem>
<MenuItem value='Music'>Music</MenuItem>
<MenuItem value='Other'>Other</MenuItem>
<MenuItem value='Unknown'>Unknown</MenuItem>
</Select>
</FormControl>
</>
) : (
<TextField
@@ -156,6 +138,25 @@ export default function RightSideComponent({
fullWidth
/>
<FormControl fullWidth>
<InputLabel id='torrent-category-select-label'>Torrent category</InputLabel>
<Select
labelId='torrent-category-select-label'
id='torrent-category-select'
value={category}
label='Torrent category'
margin='dense'
onChange={handleCategoryChange}
variant='outlined'
fullWidth
defaultValue='Unknown'
>
{torrentCategories.map(category => (
<MenuItem value={category}>{category}</MenuItem>
))}
</Select>
</FormControl>
<PosterWrapper>
<Poster poster={+isPosterUrlCorrect}>
{isPosterUrlCorrect ? <img src={posterUrl} alt='poster' /> : <NoImageIcon />}

View File

@@ -185,7 +185,14 @@ const Torrent = ({ torrent }) => {
</Dialog>
{isEditDialogOpen && (
<AddDialog hash={hash} title={title} name={name} poster={poster} handleClose={handleCloseEditDialog} />
<AddDialog
hash={hash}
title={title}
name={name}
poster={poster}
handleClose={handleCloseEditDialog}
category={category}
/>
)}
</>
)