Create upload directories on startup
This commit is contained in:
parent
783910be50
commit
fe53a6ca2c
2 changed files with 23 additions and 2 deletions
9
main.go
9
main.go
|
|
@ -21,6 +21,7 @@ import (
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
|
"github.com/Gleipnir-Technology/nidus-sync/platform/text"
|
||||||
"github.com/Gleipnir-Technology/nidus-sync/rmo"
|
"github.com/Gleipnir-Technology/nidus-sync/rmo"
|
||||||
nidussync "github.com/Gleipnir-Technology/nidus-sync/sync"
|
nidussync "github.com/Gleipnir-Technology/nidus-sync/sync"
|
||||||
|
"github.com/Gleipnir-Technology/nidus-sync/userfile"
|
||||||
"github.com/getsentry/sentry-go"
|
"github.com/getsentry/sentry-go"
|
||||||
sentryhttp "github.com/getsentry/sentry-go/http"
|
sentryhttp "github.com/getsentry/sentry-go/http"
|
||||||
"github.com/getsentry/sentry-go/zerolog"
|
"github.com/getsentry/sentry-go/zerolog"
|
||||||
|
|
@ -100,6 +101,12 @@ func main() {
|
||||||
os.Exit(6)
|
os.Exit(6)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = userfile.CreateDirectories()
|
||||||
|
if err != nil {
|
||||||
|
log.Error().Err(err).Msg("Failed to create userfile directories")
|
||||||
|
os.Exit(7)
|
||||||
|
}
|
||||||
|
|
||||||
router_logger := log.With().Logger()
|
router_logger := log.With().Logger()
|
||||||
sentryMiddleware := sentryhttp.New(sentryhttp.Options{
|
sentryMiddleware := sentryhttp.New(sentryhttp.Options{
|
||||||
Repanic: true,
|
Repanic: true,
|
||||||
|
|
@ -134,7 +141,7 @@ func main() {
|
||||||
err = llm.CreateOpenAIClient(ctx, &openai_logger)
|
err = llm.CreateOpenAIClient(ctx, &openai_logger)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("Failed to start openAI client")
|
log.Error().Err(err).Msg("Failed to start openAI client")
|
||||||
os.Exit(7)
|
os.Exit(8)
|
||||||
}
|
}
|
||||||
background.Start(ctx)
|
background.Start(ctx)
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,25 @@ import (
|
||||||
//"net/http"
|
//"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
//"github.com/Gleipnir-Technology/nidus-sync/config"
|
"github.com/Gleipnir-Technology/nidus-sync/config"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func CreateDirectories() error {
|
||||||
|
for _, subdir := range collectionToSubdir {
|
||||||
|
path := config.FilesDirectory + "/" + subdir
|
||||||
|
_, err := os.Stat(path)
|
||||||
|
if err == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(path, 0750)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Failed to create userfile directory '%s': %w", path, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func FileContentWrite(body io.Reader, collection Collection, uid uuid.UUID) error {
|
func FileContentWrite(body io.Reader, collection Collection, uid uuid.UUID) error {
|
||||||
// Create file in configured directory
|
// Create file in configured directory
|
||||||
filepath := fileContentPath(collection, uid)
|
filepath := fileContentPath(collection, uid)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue