Start work on links support
This commit is contained in:
parent
5b03a465fc
commit
435e98dac0
@ -6,6 +6,7 @@ import (
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
//TODO Transparently split to single data and header reading methods
|
||||
func (fs *WebFileSystem) readFSDocs(fileID primitive.ObjectID, fileData interface{}) (*FileHeader, error) {
|
||||
fileHeader := &FileHeader{}
|
||||
filter := primitive.M{
|
||||
|
@ -45,6 +45,28 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
|
||||
ctx.Status(http.StatusCreated)
|
||||
})
|
||||
|
||||
//TODO Support links
|
||||
route.POST("/createlink", func(ctx *gin.Context) { //TODO To PUT request
|
||||
sourcePath := ctx.Query("sourcePath")
|
||||
if sourcePath == "" {
|
||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
targetPath := ctx.Query("targetPath")
|
||||
if sourcePath == "" {
|
||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
|
||||
err := fs.CreateObjectLink(sourcePath, targetPath)
|
||||
if err != nil {
|
||||
ctx.String(http.StatusInternalServerError, err.Error()) //TODO
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Status(http.StatusCreated)
|
||||
})
|
||||
|
||||
// route.GET("writeFile", func(ctx *gin.Context) {
|
||||
// parentPath := ctx.Query("parentPath")
|
||||
// if parentPath == "" {
|
||||
|
@ -46,7 +46,12 @@ type BinaryFileData struct {
|
||||
|
||||
type PlainTextFileData struct {
|
||||
MongoId primitive.ObjectID `bson:"_id" json:"-"`
|
||||
Data string `bson:"data" json:"data"`
|
||||
Data string `bson:"data" json:"-"`
|
||||
}
|
||||
|
||||
type ObjectLinkFileData struct {
|
||||
MongoId primitive.ObjectID `bson:"_id" json:"-"`
|
||||
Link_id primitive.ObjectID `bson:"link_id" json:"-"`
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
@ -218,6 +223,50 @@ func (fs *WebFileSystem) Remove(filePath string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) CreateObjectLink(sourcePath string, linkPath string) error {
|
||||
// sourceParentPath := fs.GetParentPath(sourcePath)
|
||||
// sourceParentDirId, err := fs.FindFile(sourceParentPath)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
linkSplittedPath := fs.SplitPath(linkPath)
|
||||
linkFileName := linkSplittedPath[len(linkSplittedPath)-1]
|
||||
|
||||
linkParentDirPath := fs.GetParentPath(linkPath)
|
||||
linkParentDirPathID, err := fs.FindFile(linkParentDirPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sourceFileID, err := fs.FindFile(sourcePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newLinkHeader := FileHeader{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: linkFileName,
|
||||
Type: "objectlink",
|
||||
Icon: "",
|
||||
Data: primitive.NewObjectID(),
|
||||
}
|
||||
newLinkData := ObjectLinkFileData{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Link_id: sourceFileID,
|
||||
}
|
||||
|
||||
linkFileID, _, err := fs.Write(sourcePath, &newLinkHeader, newLinkData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = fs.AppendChildToDirectory(linkFileID, linkParentDirPathID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) SplitPath(path string) []string {
|
||||
resPath := []string{}
|
||||
splittedPath := strings.Split(path, "/")
|
||||
|
Loading…
Reference in New Issue
Block a user