mirror of
				https://github.com/zoriya/Kyoo.git
				synced 2025-11-04 03:27:14 -05:00 
			
		
		
		
	Fix insert
This commit is contained in:
		
							parent
							
								
									7f30c187b7
								
							
						
					
					
						commit
						6ab12b48b0
					
				@ -53,7 +53,7 @@ create table subtitles(
 | 
				
			|||||||
	language varchar(256),
 | 
						language varchar(256),
 | 
				
			||||||
	codec varchar(256) not null,
 | 
						codec varchar(256) not null,
 | 
				
			||||||
	extension varchar(16),
 | 
						extension varchar(16),
 | 
				
			||||||
	is_defaut boolean not null,
 | 
						is_default boolean not null,
 | 
				
			||||||
	is_forced boolean not null,
 | 
						is_forced boolean not null,
 | 
				
			||||||
	is_external boolean not null,
 | 
						is_external boolean not null,
 | 
				
			||||||
	path varchar(4096)
 | 
						path varchar(4096)
 | 
				
			||||||
 | 
				
			|||||||
@ -40,7 +40,7 @@ type MediaInfo struct {
 | 
				
			|||||||
	/// The container of the video file of this episode.
 | 
						/// The container of the video file of this episode.
 | 
				
			||||||
	Container *string `json:"container"`
 | 
						Container *string `json:"container"`
 | 
				
			||||||
	/// Version of the metadata. This can be used to invalidate older metadata from db if the extraction code has changed.
 | 
						/// Version of the metadata. This can be used to invalidate older metadata from db if the extraction code has changed.
 | 
				
			||||||
	Versions Versions
 | 
						Versions Versions `json:"versions"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// TODO: remove this
 | 
						// TODO: remove this
 | 
				
			||||||
	Video *Video
 | 
						Video *Video
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,7 @@ import (
 | 
				
			|||||||
	"github.com/golang-migrate/migrate/v4"
 | 
						"github.com/golang-migrate/migrate/v4"
 | 
				
			||||||
	"github.com/golang-migrate/migrate/v4/database/postgres"
 | 
						"github.com/golang-migrate/migrate/v4/database/postgres"
 | 
				
			||||||
	_ "github.com/golang-migrate/migrate/v4/source/file"
 | 
						_ "github.com/golang-migrate/migrate/v4/source/file"
 | 
				
			||||||
 | 
						"github.com/lib/pq"
 | 
				
			||||||
	_ "github.com/lib/pq"
 | 
						_ "github.com/lib/pq"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -96,6 +97,7 @@ func (s *MetadataService) GetMetadata(path string, sha string) (*MediaInfo, erro
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, error) {
 | 
					func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, error) {
 | 
				
			||||||
	var ret MediaInfo
 | 
						var ret MediaInfo
 | 
				
			||||||
 | 
						var fonts pq.StringArray
 | 
				
			||||||
	err := s.database.QueryRow(
 | 
						err := s.database.QueryRow(
 | 
				
			||||||
		`select i.sha, i.path, i.extension, i.mime_codec, i.size, i.duration, i.container,
 | 
							`select i.sha, i.path, i.extension, i.mime_codec, i.size, i.duration, i.container,
 | 
				
			||||||
		i.fonts, i.ver_info, i.ver_extract, i.ver_thumbs, i.ver_keyframes
 | 
							i.fonts, i.ver_info, i.ver_extract, i.ver_thumbs, i.ver_keyframes
 | 
				
			||||||
@ -103,8 +105,9 @@ func (s *MetadataService) getMetadata(path string, sha string) (*MediaInfo, erro
 | 
				
			|||||||
		sha,
 | 
							sha,
 | 
				
			||||||
	).Scan(
 | 
						).Scan(
 | 
				
			||||||
		ret.Sha, ret.Path, ret.Extension, ret.MimeCodec, ret.Size, ret.Duration, ret.Container,
 | 
							ret.Sha, ret.Path, ret.Extension, ret.MimeCodec, ret.Size, ret.Duration, ret.Container,
 | 
				
			||||||
		ret.Fonts, ret.Versions.Info, ret.Versions.Extract, ret.Versions.Thumbs, ret.Versions.Keyframes,
 | 
							fonts, ret.Versions.Info, ret.Versions.Extract, ret.Versions.Thumbs, ret.Versions.Keyframes,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
 | 
						ret.Fonts = fonts
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if err == sql.ErrNoRows || (ret.Versions.Info < InfoVersion && ret.Versions.Info != 0) {
 | 
						if err == sql.ErrNoRows || (ret.Versions.Info < InfoVersion && ret.Versions.Info != 0) {
 | 
				
			||||||
		return s.storeFreshMetadata(path, sha)
 | 
							return s.storeFreshMetadata(path, sha)
 | 
				
			||||||
@ -207,10 +210,12 @@ func (s *MetadataService) storeFreshMetadata(path string, sha string) (*MediaInf
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	tx, err := s.database.Begin()
 | 
						tx, err := s.database.Begin()
 | 
				
			||||||
	tx.Exec(
 | 
						_, err = tx.Exec(
 | 
				
			||||||
		`insert into info(sha, path, extension, mime_codec, size, duration, container, fonts, ver_info)
 | 
							`insert into info(sha, path, extension, mime_codec, size, duration, container,
 | 
				
			||||||
		values ($1, $2, $3, $4, $5, $6, $7, $8, $9)`,
 | 
							fonts, ver_info, ver_extract, ver_thumbs, ver_keyframes)
 | 
				
			||||||
		ret.Sha, ret.Path, ret.Extension, ret.MimeCodec, ret.Size, ret.Duration, ret.Container, ret.Fonts, ret.Versions.Info,
 | 
							values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)`,
 | 
				
			||||||
 | 
							ret.Sha, ret.Path, ret.Extension, ret.MimeCodec, ret.Size, ret.Duration, ret.Container,
 | 
				
			||||||
 | 
							pq.Array(ret.Fonts), ret.Versions.Info, ret.Versions.Extract, ret.Versions.Thumbs, ret.Versions.Keyframes,
 | 
				
			||||||
	)
 | 
						)
 | 
				
			||||||
	for _, v := range ret.Videos {
 | 
						for _, v := range ret.Videos {
 | 
				
			||||||
		tx.Exec(
 | 
							tx.Exec(
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user