Skip to content

Commit

Permalink
feat: add feature checkboxes to getting started page
Browse files Browse the repository at this point in the history
feat: bump version
  • Loading branch information
5rahim committed May 25, 2024
1 parent b52cddc commit 16670e8
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

- ⚡️ Reduced memory usage
- ⚡️ Automatic Transcoding cache cleanup on server startup
- ⚡️ Added more fields to getting started screen
- 🚀 Added Docker image for Linux arm64 #63
- 🚑️ Fixed occasional runtime error caused by internal module
- 💄 UI: Improved stream page layouts
Expand Down
96 changes: 96 additions & 0 deletions codegen/generated/handlers.json
Original file line number Diff line number Diff line change
Expand Up @@ -4627,6 +4627,102 @@
"returnTypescriptType": "Models_Settings"
}
},
{
"name": "HandleGettingStarted",
"trimmedName": "GettingStarted",
"comments": [
"HandleGettingStarted",
"",
"\t@summary updates the app settings.",
"\t@desc This will update the app settings.",
"\t@desc The client should re-fetch the server status after this.",
"\t@route /api/v1/start [POST]",
"\t@returns handlers.Status",
""
],
"filepath": "internal/handlers/settings.go",
"filename": "settings.go",
"api": {
"summary": "updates the app settings.",
"descriptions": [
"This will update the app settings.",
"The client should re-fetch the server status after this."
],
"endpoint": "/api/v1/start",
"methods": [
"POST"
],
"params": [],
"bodyFields": [
{
"name": "Library",
"jsonName": "library",
"goType": "models.LibrarySettings",
"usedStructType": "models.LibrarySettings",
"typescriptType": "Models_LibrarySettings",
"required": true,
"descriptions": []
},
{
"name": "MediaPlayer",
"jsonName": "mediaPlayer",
"goType": "models.MediaPlayerSettings",
"usedStructType": "models.MediaPlayerSettings",
"typescriptType": "Models_MediaPlayerSettings",
"required": true,
"descriptions": []
},
{
"name": "Torrent",
"jsonName": "torrent",
"goType": "models.TorrentSettings",
"usedStructType": "models.TorrentSettings",
"typescriptType": "Models_TorrentSettings",
"required": true,
"descriptions": []
},
{
"name": "Anilist",
"jsonName": "anilist",
"goType": "models.AnilistSettings",
"usedStructType": "models.AnilistSettings",
"typescriptType": "Models_AnilistSettings",
"required": true,
"descriptions": []
},
{
"name": "Discord",
"jsonName": "discord",
"goType": "models.DiscordSettings",
"usedStructType": "models.DiscordSettings",
"typescriptType": "Models_DiscordSettings",
"required": true,
"descriptions": []
},
{
"name": "EnableTranscode",
"jsonName": "enableTranscode",
"goType": "bool",
"usedStructType": "",
"typescriptType": "boolean",
"required": true,
"descriptions": []
},
{
"name": "EnableTorrentStreaming",
"jsonName": "enableTorrentStreaming",
"goType": "bool",
"usedStructType": "",
"typescriptType": "boolean",
"required": true,
"descriptions": []
}
],
"returns": "handlers.Status",
"returnGoType": "handlers.Status",
"returnTypescriptType": "Status"
}
},
{
"name": "HandleSaveSettings",
"trimmedName": "SaveSettings",
Expand Down
24 changes: 12 additions & 12 deletions codegen/generated/public_structs.json
Original file line number Diff line number Diff line change
Expand Up @@ -34915,9 +34915,8 @@
{
"name": "subscribers",
"jsonName": "subscribers",
"goType": "map[string]RepositorySubscriber",
"typescriptType": "Record\u003cstring, RepositorySubscriber\u003e",
"usedStructName": "mediaplayer.RepositorySubscriber",
"goType": "",
"typescriptType": "any",
"required": false,
"public": false,
"comments": []
Expand Down Expand Up @@ -36550,15 +36549,6 @@
" The current media being played."
]
},
{
"name": "transcoderSettings",
"jsonName": "transcoderSettings",
"goType": "",
"typescriptType": "any",
"required": true,
"public": false,
"comments": []
},
{
"name": "repository",
"jsonName": "repository",
Expand Down Expand Up @@ -36750,6 +36740,16 @@
"public": false,
"comments": []
},
{
"name": "reqMu",
"jsonName": "reqMu",
"goType": "sync.Mutex",
"typescriptType": "Mutex",
"usedStructName": "sync.Mutex",
"required": false,
"public": false,
"comments": []
},
{
"name": "cacheDir",
"jsonName": "cacheDir",
Expand Down
2 changes: 1 addition & 1 deletion internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package constants
import "time"

const (
Version = "1.5.0"
Version = "1.5.1"
VersionName = "Blackbeard"
GcTime = time.Minute * 30
ConfigFileName = "config.toml"
Expand Down
1 change: 1 addition & 0 deletions internal/handlers/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func InitRoutes(app *core.App, fiberApp *fiber.App) {
// Settings
v1.Get("/settings", makeHandler(app, HandleGetSettings))
v1.Patch("/settings", makeHandler(app, HandleSaveSettings))
v1.Post("/start", makeHandler(app, HandleGettingStarted))
v1.Patch("/settings/list-sync", makeHandler(app, HandleSaveListSyncSettings))
v1.Patch("/settings/auto-downloader", makeHandler(app, HandleSaveAutoDownloaderSettings))

Expand Down
81 changes: 81 additions & 0 deletions internal/handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,87 @@ func HandleGetSettings(c *RouteCtx) error {
return c.RespondWithData(settings)
}

// HandleGettingStarted
//
// @summary updates the app settings.
// @desc This will update the app settings.
// @desc The client should re-fetch the server status after this.
// @route /api/v1/start [POST]
// @returns handlers.Status
func HandleGettingStarted(c *RouteCtx) error {

type body struct {
Library models.LibrarySettings `json:"library"`
MediaPlayer models.MediaPlayerSettings `json:"mediaPlayer"`
Torrent models.TorrentSettings `json:"torrent"`
Anilist models.AnilistSettings `json:"anilist"`
Discord models.DiscordSettings `json:"discord"`
EnableTranscode bool `json:"enableTranscode"`
EnableTorrentStreaming bool `json:"enableTorrentStreaming"`
}
var b body

if err := c.Fiber.BodyParser(&b); err != nil {
return c.RespondWithError(err)
}

listSyncSettings := &models.ListSyncSettings{}
autoDownloaderSettings := &models.AutoDownloaderSettings{}
prevSettings, err := c.App.Database.GetSettings()
if err == nil && prevSettings.ListSync != nil {
listSyncSettings = prevSettings.ListSync
}
if err == nil && prevSettings.AutoDownloader != nil {
autoDownloaderSettings = prevSettings.AutoDownloader
}

settings, err := c.App.Database.UpsertSettings(&models.Settings{
BaseModel: models.BaseModel{
ID: 1,
UpdatedAt: time.Now(),
},
Library: &b.Library,
MediaPlayer: &b.MediaPlayer,
Torrent: &b.Torrent,
Anilist: &b.Anilist,
Discord: &b.Discord,
ListSync: listSyncSettings,
AutoDownloader: autoDownloaderSettings,
})

if err != nil {
return c.RespondWithError(err)
}

go func() {
if b.EnableTranscode {
stt := c.App.SecondarySettings.Mediastream
stt.TranscodeEnabled = true
_, err = c.App.Database.UpsertMediastreamSettings(stt)
if err != nil {
c.App.Logger.Error().Err(err).Msg("app: Failed to update mediastream settings")
}
}
if b.EnableTorrentStreaming {
stt := c.App.SecondarySettings.Torrentstream
stt.Enabled = true
_, err = c.App.Database.UpsertTorrentstreamSettings(stt)
if err != nil {
c.App.Logger.Error().Err(err).Msg("app: Failed to update mediastream settings")
}
}
}()

c.App.WSEventManager.SendEvent("settings", settings)

status := NewStatus(c)

// Refresh modules that depend on the settings
c.App.InitOrRefreshModules()

return c.RespondWithData(status)
}

// HandleSaveSettings
//
// @summary updates the app settings.
Expand Down
17 changes: 17 additions & 0 deletions seanime-web/src/api/generated/endpoint.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,23 @@ export type ScanLocalFiles_Variables = {
// settings
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/**
* - Filepath: internal/handlers/settings.go
* - Filename: settings.go
* - Endpoint: /api/v1/start
* @description
* Route updates the app settings.
*/
export type GettingStarted_Variables = {
library: Models_LibrarySettings
mediaPlayer: Models_MediaPlayerSettings
torrent: Models_TorrentSettings
anilist: Models_AnilistSettings
discord: Models_DiscordSettings
enableTranscode: boolean
enableTorrentStreaming: boolean
}

/**
* - Filepath: internal/handlers/settings.go
* - Filename: settings.go
Expand Down
11 changes: 11 additions & 0 deletions seanime-web/src/api/generated/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,17 @@ export const API_ENDPOINTS = {
methods: ["GET"],
endpoint: "/api/v1/settings",
},
/**
* @description
* Route updates the app settings.
* This will update the app settings.
* The client should re-fetch the server status after this.
*/
GettingStarted: {
key: "SETTINGS-getting-started",
methods: ["POST"],
endpoint: "/api/v1/start",
},
/**
* @description
* Route updates the app settings.
Expand Down
11 changes: 11 additions & 0 deletions seanime-web/src/api/generated/hooks_template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,17 @@
// })
// }

// export function useGettingStarted() {
// return useServerMutation<Status, GettingStarted_Variables>({
// endpoint: API_ENDPOINTS.SETTINGS.GettingStarted.endpoint,
// method: API_ENDPOINTS.SETTINGS.GettingStarted.methods[0],
// mutationKey: [API_ENDPOINTS.SETTINGS.GettingStarted.key],
// onSuccess: async () => {
//
// },
// })
// }

// export function useSaveSettings() {
// return useServerMutation<Status, SaveSettings_Variables>({
// endpoint: API_ENDPOINTS.SETTINGS.SaveSettings.endpoint,
Expand Down
21 changes: 20 additions & 1 deletion seanime-web/src/api/hooks/settings.hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { useServerMutation, useServerQuery } from "@/api/client/requests"
import { SaveAutoDownloaderSettings_Variables, SaveListSyncSettings_Variables, SaveSettings_Variables } from "@/api/generated/endpoint.types"
import {
GettingStarted_Variables,
SaveAutoDownloaderSettings_Variables,
SaveListSyncSettings_Variables,
SaveSettings_Variables,
} from "@/api/generated/endpoint.types"
import { API_ENDPOINTS } from "@/api/generated/endpoints"
import { Models_Settings, Status } from "@/api/generated/types"
import { useQueryClient } from "@tanstack/react-query"
Expand All @@ -14,6 +19,20 @@ export function useGetSettings() {
})
}

export function useGettingStarted() {
const queryClient = useQueryClient()

return useServerMutation<Status, GettingStarted_Variables>({
endpoint: API_ENDPOINTS.SETTINGS.GettingStarted.endpoint,
method: API_ENDPOINTS.SETTINGS.GettingStarted.methods[0],
mutationKey: [API_ENDPOINTS.SETTINGS.GettingStarted.key],
onSuccess: async () => {
await queryClient.invalidateQueries({ queryKey: [API_ENDPOINTS.SETTINGS.GetSettings.key] })
await queryClient.invalidateQueries({ queryKey: [API_ENDPOINTS.STATUS.GetStatus.key] })
},
})
}

export function useSaveSettings() {
const queryClient = useQueryClient()

Expand Down
Loading

0 comments on commit 16670e8

Please sign in to comment.