mirror of https://github.com/Xhofe/alist
Merge 8036a7faee
into 4f8bc478d5
commit
4ed09269f8
|
@ -3,6 +3,7 @@ package gofile
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/errs"
|
"github.com/alist-org/alist/v3/internal/errs"
|
||||||
|
@ -97,9 +98,18 @@ func (d *Gofile) Link(ctx context.Context, file model.Obj, args model.LinkArgs)
|
||||||
return nil, fmt.Errorf("failed to create direct link: %w", err)
|
return nil, fmt.Errorf("failed to create direct link: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return &model.Link{
|
// Configure cache expiration based on user setting
|
||||||
|
link := &model.Link{
|
||||||
URL: directLink,
|
URL: directLink,
|
||||||
}, nil
|
}
|
||||||
|
|
||||||
|
// Only set expiration if LinkExpiry > 0 (0 means no caching)
|
||||||
|
if d.LinkExpiry > 0 {
|
||||||
|
expiration := time.Duration(d.LinkExpiry) * 24 * time.Hour
|
||||||
|
link.Expiration = &expiration
|
||||||
|
}
|
||||||
|
|
||||||
|
return link, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Gofile) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
|
func (d *Gofile) MakeDir(ctx context.Context, parentDir model.Obj, dirName string) (model.Obj, error) {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import (
|
||||||
type Addition struct {
|
type Addition struct {
|
||||||
driver.RootID
|
driver.RootID
|
||||||
APIToken string `json:"api_token" required:"true" help:"Get your API token from your Gofile profile page"`
|
APIToken string `json:"api_token" required:"true" help:"Get your API token from your Gofile profile page"`
|
||||||
|
LinkExpiry int `json:"link_expiry" type:"number" default:"30" help:"Direct link cache duration in days. Set to 0 to disable caching"`
|
||||||
|
DirectLinkExpiry int `json:"direct_link_expiry" type:"number" default:"0" help:"Direct link expiration time in hours on Gofile server. Set to 0 for no expiration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var config = driver.Config{
|
var config = driver.Config{
|
||||||
|
|
|
@ -10,10 +10,12 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/alist-org/alist/v3/drivers/base"
|
"github.com/alist-org/alist/v3/drivers/base"
|
||||||
"github.com/alist-org/alist/v3/internal/driver"
|
"github.com/alist-org/alist/v3/internal/driver"
|
||||||
"github.com/alist-org/alist/v3/internal/model"
|
"github.com/alist-org/alist/v3/internal/model"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -137,9 +139,10 @@ func (d *Gofile) deleteJSON(ctx context.Context, endpoint string, data interface
|
||||||
|
|
||||||
func (d *Gofile) handleError(resp *http.Response) error {
|
func (d *Gofile) handleError(resp *http.Response) error {
|
||||||
body, _ := io.ReadAll(resp.Body)
|
body, _ := io.ReadAll(resp.Body)
|
||||||
|
log.Debugf("Gofile API error (HTTP %d): %s", resp.StatusCode, string(body))
|
||||||
|
|
||||||
var errorResp ErrorResponse
|
var errorResp ErrorResponse
|
||||||
if err := json.Unmarshal(body, &errorResp); err == nil {
|
if err := json.Unmarshal(body, &errorResp); err == nil && errorResp.Status == "error" {
|
||||||
return fmt.Errorf("gofile API error: %s (code: %s)", errorResp.Error.Message, errorResp.Error.Code)
|
return fmt.Errorf("gofile API error: %s (code: %s)", errorResp.Error.Message, errorResp.Error.Code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +202,11 @@ func (d *Gofile) uploadFile(ctx context.Context, folderId string, file model.Fil
|
||||||
func (d *Gofile) createDirectLink(ctx context.Context, contentId string) (string, error) {
|
func (d *Gofile) createDirectLink(ctx context.Context, contentId string) (string, error) {
|
||||||
data := map[string]interface{}{}
|
data := map[string]interface{}{}
|
||||||
|
|
||||||
|
if d.DirectLinkExpiry > 0 {
|
||||||
|
expireTime := time.Now().Add(time.Duration(d.DirectLinkExpiry) * time.Hour).Unix()
|
||||||
|
data["expireTime"] = expireTime
|
||||||
|
}
|
||||||
|
|
||||||
var result DirectLinkResponse
|
var result DirectLinkResponse
|
||||||
err := d.postJSON(ctx, fmt.Sprintf("/contents/%s/directlinks", contentId), data, &result)
|
err := d.postJSON(ctx, fmt.Sprintf("/contents/%s/directlinks", contentId), data, &result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue