mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 19:16:24 +00:00
- 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.
79 lines
2.1 KiB
Go
79 lines
2.1 KiB
Go
package filedriver
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/cloudwego/hertz/pkg/app"
|
|
"github.com/snowykami/neo-blog/pkg/constant"
|
|
"github.com/snowykami/neo-blog/pkg/resps"
|
|
|
|
"io"
|
|
"os"
|
|
"path"
|
|
|
|
"github.com/studio-b12/gowebdav"
|
|
)
|
|
|
|
type WebDAVClientDriver struct {
|
|
client *gowebdav.Client
|
|
config *DriverConfig
|
|
BasePath string
|
|
}
|
|
|
|
func NewWebDAVClientDriver(driverConfig *DriverConfig) *WebDAVClientDriver {
|
|
c := gowebdav.NewClient(driverConfig.WebDavUrl, driverConfig.WebDavUser, driverConfig.WebDavPassword)
|
|
return &WebDAVClientDriver{client: c, BasePath: driverConfig.BasePath, config: driverConfig}
|
|
}
|
|
|
|
func (d *WebDAVClientDriver) fullPath(p string) string {
|
|
if d.BasePath == "" {
|
|
return p
|
|
}
|
|
return path.Join(d.BasePath, p)
|
|
}
|
|
|
|
func (d *WebDAVClientDriver) Save(ctx *app.RequestContext, p string, r io.Reader) error {
|
|
data, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return d.client.Write(d.fullPath(p), data, 0644)
|
|
}
|
|
|
|
func (d *WebDAVClientDriver) Open(ctx *app.RequestContext, p string) (io.ReadCloser, error) {
|
|
data, err := d.client.Read(d.fullPath(p))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return io.NopCloser(bytes.NewReader(data)), nil
|
|
}
|
|
|
|
func (d *WebDAVClientDriver) Get(ctx *app.RequestContext, p string) {
|
|
if d.config.WebDavPolicy == constant.WebdavPolicyRedirect {
|
|
ctx.Redirect(302, []byte(d.config.WebDavUrl+d.fullPath(p)))
|
|
return
|
|
} else {
|
|
data, err := d.client.Read(d.fullPath(p))
|
|
if err != nil {
|
|
resps.InternalServerError(ctx, err.Error())
|
|
return
|
|
}
|
|
ctx.SetBodyStream(bytes.NewReader(data), len(data))
|
|
ctx.Response.Header.Set("Content-Type", "application/octet-stream")
|
|
ctx.Response.Header.Set("Content-Length", fmt.Sprintf("%d", len(data)))
|
|
}
|
|
}
|
|
|
|
func (d *WebDAVClientDriver) Delete(ctx *app.RequestContext, p string) error {
|
|
return d.client.Remove(d.fullPath(p))
|
|
}
|
|
|
|
func (d *WebDAVClientDriver) Stat(ctx *app.RequestContext, p string) (os.FileInfo, error) {
|
|
return d.client.Stat(d.fullPath(p))
|
|
}
|
|
|
|
func (d *WebDAVClientDriver) ListDir(ctx *app.RequestContext, p string) ([]os.FileInfo, error) {
|
|
return d.client.ReadDir(d.fullPath(p))
|
|
}
|