Notify user if files too large

This commit is contained in:
Keroosha 2023-04-13 23:59:45 +03:00
parent a353ee0f3b
commit 0d97e405b4
2 changed files with 32 additions and 15 deletions

View File

@ -1,6 +1,6 @@
[Unit]
# A short human readable title of the unit
Description= Keroosha.SilencerBot Prod
Description=Keroosha.SilencerBot Prod
# A list of units whose activations will occur before this unit starts.
After=network.target
@ -13,9 +13,13 @@ After=network.target
Type=simple
# Command with arguments to invoke when the unit is activated.
ExecStart=/opt/apps/Keroosha.SilncerBot/app/Keroosha.SilencerBot
WorkingDirectory=/opt/apps/Keroosha.SilncerBot/app
# Configures under what conditions the unit will be restarted.
Restart=on-failure
User=apps
Restart=always
CPUQuota=15%
KillSignal=SIGINT
Environment=SILENCER_BOT_CONFIG_PATH=/opt/apps/Keroosha.SilncerBot/config/config.json
[Install]
# A list of units who when activated will try and activate this unit

View File

@ -121,19 +121,32 @@ let processUploading (job: UserJob, botConfig: Funogram.Types.BotConfig, config:
async {
let ctx = getContext job
let instrumentalPath, vocalsPath = getArtifactsPath ctx
use fInstrumental = File.OpenRead instrumentalPath
use fVocals = File.OpenRead vocalsPath
let media = [|
InputFile.File (Path.GetFileName instrumentalPath, fInstrumental)
InputFile.File (Path.GetFileName vocalsPath, fVocals)
|]
Logging.logger.Information $"Uploading results for {job.Id} job"
// TODO Error handling!
let uploadMedia (x: InputFile) = TgClient.makeRequestAsync botConfig <| Api.sendAudio (ctx.chatId) (x) (0)
do! media |> Seq.map uploadMedia |> Async.Sequential |> Async.Ignore
return { job with State = JobState.CleanUp }
let sizeCheck = [
FileInfo(instrumentalPath)
FileInfo(vocalsPath) ]
|> List.map (fun x -> Math.Floor(double(x.Length) / double(Math.Pow(1024, 2))))
|> List.fold (fun acc x -> acc && x < double(50)) true
match sizeCheck with
| false ->
do! TgClient.makeRequestAsync botConfig <| Api.sendMessage ctx.chatId "Не могу загрузить результаты - они весят больше 50мб"
|> Async.Ignore
return { job with State = JobState.CleanUp }
| true ->
use fInstrumental = File.OpenRead instrumentalPath
use fVocals = File.OpenRead vocalsPath
let media = [|
InputFile.File (Path.GetFileName instrumentalPath, fInstrumental)
InputFile.File (Path.GetFileName vocalsPath, fVocals)
|]
Logging.logger.Information $"Uploading results for {job.Id} job"
// TODO Error handling!
let uploadMedia (x: InputFile) = TgClient.makeRequestAsync botConfig <| Api.sendAudio (ctx.chatId) (x) (0)
do! media |> Seq.map uploadMedia |> Async.Sequential |> Async.Ignore
return { job with State = JobState.CleanUp }
}
let processCleanUp (job: UserJob, botConfig: Funogram.Types.BotConfig, config: BotConfig) =