Skip to content

Commit

Permalink
implemented database config
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirari04 committed Jan 14, 2024
1 parent 977d7da commit f0fe0ac
Show file tree
Hide file tree
Showing 5 changed files with 395 additions and 236 deletions.
7 changes: 5 additions & 2 deletions cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"ch/kirari04/videocms/config"
"ch/kirari04/videocms/configdb"
"ch/kirari04/videocms/helpers"
"ch/kirari04/videocms/inits"
"log"
Expand All @@ -21,10 +22,12 @@ func Init() {
}
os.Exit(1)
}
//setup captcha
inits.Captcha()
// for setting up the database connection
inits.Database()
// for migrating all the models
inits.Models()
// for setting up configuration from db
configdb.Setup()
//setup captcha
inits.Captcha()
}
291 changes: 57 additions & 234 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,79 +1,79 @@
package config

import (
"ch/kirari04/videocms/models"
"log"
"os"
"strconv"
)

type Config struct {
AppName string `validate:"required,min=1,max=120"`
Host string `validate:"required,min=1,max=120"`
Host string `validate:"required,min=1,max=120"`

Project string `validate:"required,min=1,max=512"`
ProjectDocumentation string `validate:"required,min=1,max=512"`
ProjectDownload string `validate:"required,min=1,max=512"`
AppName string

JwtSecretKey string `validate:"required,min=8,max=512"`
JwtUploadSecretKey string `validate:"required,min=8,max=512"`
Project string
ProjectDocumentation string
ProjectDownload string

CookieDomain string `validate:"required,min=8,max=225"`
JwtSecretKey string
JwtUploadSecretKey string

ReloadHtml *bool `validate:"required,boolean"`
EncodingEnabled *bool `validate:"required,boolean"`
UploadEnabled *bool `validate:"required,boolean"`
RatelimitEnabled *bool `validate:"required,boolean"`
CloudflareEnabled *bool `validate:"required,boolean"`
CookieDomain string

MaxItemsMultiDelete int64 `validate:"required,number,min=1"`
MaxRunningEncodes int64 `validate:"required,number,min=1"`
ReloadHtml *bool
EncodingEnabled *bool
UploadEnabled *bool
RatelimitEnabled *bool
CloudflareEnabled *bool

MaxUploadFilesize int64 `validate:"required,number,min=1"`
MaxUploadChuncksize int64 `validate:"required,number,min=1"`
MaxUploadSessions int64 `validate:"required,number,min=1"`
MaxPostSize int64 `validate:"required,number,min=1"`
MaxItemsMultiDelete int64
MaxRunningEncodes int64

MaxUploadFilesize int64
MaxUploadChuncksize int64
MaxUploadSessions int64
MaxPostSize int64

FolderVideoQualitysPub string `validate:"required,min=1,max=255"`
FolderVideoQualitysPriv string `validate:"required,min=1,max=255"`
FolderVideoUploadsPriv string `validate:"required,min=1,max=255"`

CorsAllowOrigins string `validate:"required,min=1"`
CorsAllowHeaders string `validate:"required,min=1"`
CorsAllowCredentials *bool `validate:"required,boolean"`

CaptchaEnabled *bool `validate:"required,boolean"`
CaptchaType string `validate:"required_if=CaptchaEnabled 1,omitempty,min=1,max=10"`
Captcha_Recaptcha_PrivateKey string `validate:"required_if=CaptchaType recaptcha,omitempty,min=1,max=40"`
Captcha_Recaptcha_PublicKey string `validate:"required_if=CaptchaType recaptcha,omitempty,min=1,max=40"`
Captcha_Hcaptcha_PrivateKey string `validate:"required_if=CaptchaType hcaptcha,omitempty,min=1,max=42"`
Captcha_Hcaptcha_PublicKey string `validate:"required_if=CaptchaType hcaptcha,omitempty,uuid_rfc4122"`

EncodeHls240p *bool `validate:"required,boolean"`
EncodeHls360p *bool `validate:"required,boolean"`
EncodeHls480p *bool `validate:"required,boolean"`
EncodeHls720p *bool `validate:"required,boolean"`
EncodeHls1080p *bool `validate:"required,boolean"`
EncodeHls1440p *bool `validate:"required,boolean"`
EncodeHls2160p *bool `validate:"required,boolean"`
EncodeAv1 *bool `validate:"required,boolean"`
EncodeVp9 *bool `validate:"required,boolean"`
EncodeH264 *bool `validate:"required,boolean"`

FFmpegAv1AudioCodec string `validate:"required,min=1"`
FFmpegVp9AudioCodec string `validate:"required,min=1"`
FFmpegH264AudioCodec string `validate:"required,min=1"`

FFmpegAv1Crf int `validate:"required,number,min=1,max=50"`
FFmpegVp9Crf int `validate:"required,number,min=1,max=50"`
FFmpegH264Crf int `validate:"required,number,min=1,max=50"`

FFmpegAv1Height int64 `validate:"required,number,min=1"`
FFmpegAv1Width int64 `validate:"required,number,min=1"`
FFmpegVp9Height int64 `validate:"required,number,min=1"`
FFmpegVp9Width int64 `validate:"required,number,min=1"`
FFmpegH264Height int64 `validate:"required,number,min=1"`
FFmpegH264Width int64 `validate:"required,number,min=1"`
CorsAllowOrigins string
CorsAllowHeaders string
CorsAllowCredentials *bool

CaptchaEnabled *bool
CaptchaType string
Captcha_Recaptcha_PrivateKey string
Captcha_Recaptcha_PublicKey string
Captcha_Hcaptcha_PrivateKey string
Captcha_Hcaptcha_PublicKey string

EncodeHls240p *bool
EncodeHls360p *bool
EncodeHls480p *bool
EncodeHls720p *bool
EncodeHls1080p *bool
EncodeHls1440p *bool
EncodeHls2160p *bool
EncodeAv1 *bool
EncodeVp9 *bool
EncodeH264 *bool

FFmpegAv1AudioCodec string
FFmpegVp9AudioCodec string
FFmpegH264AudioCodec string

FFmpegAv1Crf int
FFmpegVp9Crf int
FFmpegH264Crf int

FFmpegAv1Height int64
FFmpegAv1Width int64
FFmpegVp9Height int64
FFmpegVp9Width int64
FFmpegH264Height int64
FFmpegH264Width int64
}

type PublicConfig struct {
Expand Down Expand Up @@ -122,191 +122,14 @@ var EXTENSIONS []string = []string{
}

func Setup() {
ENV.AppName = getEnv("AppName", "VideoCMS")
ENV.Host = getEnv("Host", ":3000")

ENV.Project = getEnv("Project", "https://github.com/notfound")
ENV.ProjectDocumentation = getEnv("ProjectDocumentation", "https://github.com/notfound")
ENV.ProjectDownload = getEnv("ProjectDownload", "https://github.com/notfound")

ENV.JwtSecretKey = getEnv("JwtSecretKey", "secretkey")
ENV.JwtUploadSecretKey = getEnv("JwtUploadSecretKey", "secretkeyupload")

ENV.CookieDomain = getEnv("CookieDomain", "secretkey")

ENV.ReloadHtml = getEnv_bool("ReloadHtml", boolPtr(false))
ENV.EncodingEnabled = getEnv_bool("EncodingEnabled", boolPtr(true))
ENV.UploadEnabled = getEnv_bool("UploadEnabled", boolPtr(true))
ENV.RatelimitEnabled = getEnv_bool("RatelimitEnabled", boolPtr(false))
ENV.CloudflareEnabled = getEnv_bool("CloudflareEnabled", boolPtr(false))

ENV.MaxItemsMultiDelete = getEnv_int64("MaxItemsMultiDelete", 1000)
ENV.MaxRunningEncodes = getEnv_int64("MaxRunningEncodes", 1)

ENV.MaxUploadFilesize = getEnv_int64("MaxUploadFilesize", 5*1024*1024*1024) // 5gb
ENV.MaxUploadChuncksize = getEnv_int64("MaxUploadChuncksize", 20*1024*1024) // 20mb
ENV.MaxUploadSessions = getEnv_int64("MaxUploadSessions", 10)
ENV.MaxPostSize = getEnv_int64("MaxPostSize", 100*1024*1024) // 100mb

ENV.FolderVideoQualitysPriv = getEnv("FolderVideoQualitysPriv", "./videos/qualitys")
ENV.FolderVideoQualitysPub = getEnv("FolderVideoQualitysPub", "/videos/qualitys")
ENV.FolderVideoUploadsPriv = getEnv("FolderVideoUploadsPriv", "./videos/uploads")

ENV.CorsAllowHeaders = getEnv("CorsAllowHeaders", "*")
ENV.CorsAllowOrigins = getEnv("CorsAllowOrigins", "*")
ENV.CorsAllowCredentials = getEnv_bool("CorsAllowCredentials", boolPtr(true))

ENV.CaptchaEnabled = getEnv_bool("CaptchaEnabled", boolPtr(false))
ENV.CaptchaType = getEnv("CaptchaType", "")
ENV.Captcha_Recaptcha_PrivateKey = getEnv("Captcha_Recaptcha_PrivateKey", "")
ENV.Captcha_Recaptcha_PublicKey = getEnv("Captcha_Recaptcha_PublicKey", "")
ENV.Captcha_Hcaptcha_PrivateKey = getEnv("Captcha_Hcaptcha_PrivateKey", "")
ENV.Captcha_Hcaptcha_PublicKey = getEnv("Captcha_Hcaptcha_PublicKey", "")

ENV.EncodeHls240p = getEnv_bool("EncodeHls240p", boolPtr(true))
ENV.EncodeHls360p = getEnv_bool("EncodeHls360p", boolPtr(true))
ENV.EncodeHls480p = getEnv_bool("EncodeHls480p", boolPtr(true))
ENV.EncodeHls720p = getEnv_bool("EncodeHls720p", boolPtr(true))
ENV.EncodeHls1080p = getEnv_bool("EncodeHls1080p", boolPtr(true))
ENV.EncodeHls1440p = getEnv_bool("EncodeHls1440p", boolPtr(false))
ENV.EncodeHls2160p = getEnv_bool("EncodeHls2160p", boolPtr(false))
ENV.EncodeAv1 = getEnv_bool("EncodeAv1", boolPtr(false))
ENV.EncodeVp9 = getEnv_bool("EncodeVp9", boolPtr(false))
ENV.EncodeH264 = getEnv_bool("EncodeH264", boolPtr(false))

ENV.FFmpegAv1AudioCodec = getEnv("FFmpegAv1AudioCodec", "aac")
ENV.FFmpegVp9AudioCodec = getEnv("FFmpegVp9AudioCodec", "libopus")
ENV.FFmpegH264AudioCodec = getEnv("FFmpegH264AudioCodec", "aac")

ENV.FFmpegAv1Crf = getEnv_int("FFmpegAv1Crf", 30)
ENV.FFmpegVp9Crf = getEnv_int("FFmpegVp9Crf", 30)
ENV.FFmpegH264Crf = getEnv_int("FFmpegH264Crf", 30)

ENV.FFmpegAv1Height = getEnv_int64("FFmpegAv1Height", 480)
ENV.FFmpegAv1Width = getEnv_int64("FFmpegAv1Width", 854)
ENV.FFmpegVp9Height = getEnv_int64("FFmpegVp9Height", 480)
ENV.FFmpegVp9Width = getEnv_int64("FFmpegVp9Width", 854)
ENV.FFmpegH264Height = getEnv_int64("FFmpegH264Height", 480)
ENV.FFmpegH264Width = getEnv_int64("FFmpegH264Width", 854)

models.AvailableQualitys = []models.AvailableQuality{
{
Name: "240p",
FolderName: "240p",
Height: 240,
Width: 426,
Crf: 30,
Type: "hls",
Muted: true,
OutputFile: "out.m3u8",
Enabled: *ENV.EncodeHls240p,
},
{
Name: "360p",
FolderName: "360p",
Height: 360,
Width: 640,
Crf: 26,
Type: "hls",
Muted: true,
OutputFile: "out.m3u8",
Enabled: *ENV.EncodeHls360p,
},
{
Name: "480p",
FolderName: "480p",
Height: 480,
Width: 854,
Crf: 26,
Type: "hls",
Muted: true,
OutputFile: "out.m3u8",
Enabled: *ENV.EncodeHls480p,
},
{
Name: "720p",
FolderName: "720p",
Height: 720,
Width: 1280,
Crf: 26,
Type: "hls",
Muted: true,
OutputFile: "out.m3u8",
Enabled: *ENV.EncodeHls720p,
},
{
Name: "1080p",
FolderName: "1080p",
Height: 1080,
Width: 1920,
Crf: 24,
Type: "hls",
Muted: true,
OutputFile: "out.m3u8",
Enabled: *ENV.EncodeHls1080p,
},
{
Name: "1440p",
FolderName: "1440p",
Height: 1440,
Width: 2560,
Crf: 24,
Type: "hls",
Muted: true,
OutputFile: "out.m3u8",
Enabled: *ENV.EncodeHls1440p,
},
{
Name: "2160p",
FolderName: "2160p",
Height: 2160,
Width: 3840,
Crf: 24,
Type: "hls",
Muted: true,
OutputFile: "out.m3u8",
Enabled: *ENV.EncodeHls2160p,
},
// downloads
{
Name: "av1",
FolderName: "av1",
Height: ENV.FFmpegAv1Height,
Width: ENV.FFmpegAv1Width,
Crf: ENV.FFmpegAv1Crf,
Type: "av1",
Muted: false,
AudioCodec: ENV.FFmpegAv1AudioCodec,
OutputFile: "out.mp4",
Enabled: *ENV.EncodeAv1,
},
{
Name: "vp9",
FolderName: "vp9",
Height: ENV.FFmpegVp9Height,
Width: ENV.FFmpegVp9Width,
Crf: ENV.FFmpegVp9Crf,
Type: "vp9",
Muted: false,
AudioCodec: ENV.FFmpegVp9AudioCodec,
OutputFile: "out.webm",
Enabled: *ENV.EncodeVp9,
},
{
Name: "h264",
FolderName: "h264",
Height: ENV.FFmpegH264Height,
Width: ENV.FFmpegH264Width,
Crf: ENV.FFmpegH264Crf,
Type: "h264",
Muted: false,
AudioCodec: ENV.FFmpegH264AudioCodec,
OutputFile: "out.mp4",
Enabled: *ENV.EncodeH264,
},
}
}

// getters
func getEnv(key string, defaultValue string) string {
if value := os.Getenv(key); value != "" {
return value
Expand Down
Loading

0 comments on commit f0fe0ac

Please sign in to comment.