Files
neo-blog/pkg/filedriver/local_driver.go
Snowykami 709aa82337 feat: add new color themes and styles for rose, violet, and yellow
- Introduced new CSS files for rose, violet, and yellow themes with custom color variables.
- Implemented dark mode styles for each theme.
- Created a color data structure to manage theme colors in the console settings.

feat: implement image cropper component

- Added an image cropper component for user profile picture editing.
- Integrated the image cropper into the user profile page.

feat: enhance console sidebar with user permissions

- Defined sidebar items with permission checks for admin and editor roles.
- Updated user center navigation to reflect user permissions.

feat: add user profile and security settings

- Developed user profile page with avatar upload and editing functionality.
- Implemented user security settings for password and email verification.

feat: create reusable dialog and OTP input components

- Built a dialog component for modal interactions.
- Developed an OTP input component for email verification.

fix: improve file handling utilities

- Added utility functions for file URI generation.
- Implemented permission checks for user roles in the common utilities.
2025-09-20 12:45:10 +08:00

76 lines
1.6 KiB
Go

package filedriver
import (
"io"
"os"
"path/filepath"
"github.com/cloudwego/hertz/pkg/app"
)
type LocalDriver struct {
BasePath string
}
func NewLocalDriver(driverConfig *DriverConfig) *LocalDriver {
return &LocalDriver{
BasePath: driverConfig.BasePath,
}
}
func (d *LocalDriver) fullPath(path string) string {
return filepath.Join(d.BasePath, path)
}
func (d *LocalDriver) Save(ctx *app.RequestContext, path string, r io.Reader) error {
full := d.fullPath(path)
if err := os.MkdirAll(filepath.Dir(full), 0755); err != nil {
return err
}
f, err := os.Create(full)
if err != nil {
return err
}
defer func(f *os.File) {
err := f.Close()
if err != nil {
}
}(f)
_, err = io.Copy(f, r)
return err
}
func (d *LocalDriver) Open(ctx *app.RequestContext, path string) (io.ReadCloser, error) {
return os.Open(d.fullPath(path))
}
func (d *LocalDriver) Get(ctx *app.RequestContext, path string) {
ctx.File(d.fullPath(path))
ctx.Abort()
}
func (d *LocalDriver) Delete(ctx *app.RequestContext, path string) error {
return os.Remove(d.fullPath(path))
}
func (d *LocalDriver) Stat(ctx *app.RequestContext, path string) (os.FileInfo, error) {
return os.Stat(d.fullPath(path))
}
func (d *LocalDriver) ListDir(ctx *app.RequestContext, path string) ([]os.FileInfo, error) {
entries, err := os.ReadDir(d.fullPath(path))
if err != nil {
return nil, err
}
infos := make([]os.FileInfo, 0, len(entries))
for _, entry := range entries {
info, err := entry.Info()
if err != nil {
return nil, err
}
infos = append(infos, info)
}
return infos, nil
}