-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement ApplyApiPathRule and update path handling in artwork …
…and picture routes
- Loading branch information
Showing
12 changed files
with
88 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package storage | ||
|
||
import ( | ||
"errors" | ||
"path" | ||
"strings" | ||
|
||
"github.com/krau/ManyACG/config" | ||
"github.com/krau/ManyACG/types" | ||
) | ||
|
||
var ( | ||
ErrNilStorageDetail = errors.New("storage detail is nil") | ||
ErrStorageNotFound = errors.New("storage not found") | ||
) | ||
|
||
func applyRule(detail *types.StorageDetail) (*types.StorageDetail, error) { | ||
if detail == nil { | ||
return nil, ErrNilStorageDetail | ||
} | ||
|
||
currentType := detail.Type.String() | ||
currentPath := detail.Path | ||
|
||
if currentType == "" || currentPath == "" { | ||
return detail, nil | ||
} | ||
|
||
for _, rule := range config.Cfg.Storage.Rules { | ||
if !(currentType == rule.StorageType && strings.HasPrefix(currentPath, rule.PathPrefix)) { | ||
continue | ||
} | ||
if rule.RewriteStorage == "" { | ||
continue | ||
} | ||
_, ok := Storages[types.StorageType(rule.RewriteStorage)] | ||
if !ok { | ||
return nil, ErrStorageNotFound | ||
} | ||
detail.Type = types.StorageType(rule.RewriteStorage) | ||
detail.Path = path.Join(rule.JoinPrefix, strings.TrimPrefix(currentPath, rule.TrimPrefix)) | ||
} | ||
return detail, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters