Create pathlinks
This commit is contained in:
parent
2a5f0bb3f4
commit
f363ebbe10
@ -34,46 +34,11 @@ func (f *FinderApplication) Render(isMobile bool) gin.H {
|
|||||||
return gin.H{}
|
return gin.H{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FinderApplication) RenderPrivateContextMenu(context string, filePath string, data string) gin.H {
|
|
||||||
islands := [][]wde.ContexMenuRow{}
|
|
||||||
islands = append(islands, []wde.ContexMenuRow{})
|
|
||||||
|
|
||||||
if context == "FileTileView" {
|
|
||||||
islands = append(islands, []wde.ContexMenuRow{
|
|
||||||
{Label: "Get Info", Action: "getInfo"},
|
|
||||||
{Label: "New Directory", Action: "createDir"},
|
|
||||||
})
|
|
||||||
return gin.H{
|
|
||||||
"Islands": islands,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch context {
|
|
||||||
case "directory":
|
|
||||||
if f.fs.GetExtension(filePath) == "app" {
|
|
||||||
islands = append(islands, []wde.ContexMenuRow{
|
|
||||||
{Label: "Open as Directory", Action: "openAsDir"},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
islands = append(islands, []wde.ContexMenuRow{
|
|
||||||
{Label: "temp Menu 1", Action: ""},
|
|
||||||
{Label: "temp Menu 2", Action: ""},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
islands = append(islands, []wde.ContexMenuRow{
|
|
||||||
{Label: "Delete File", Action: "deleteFile"},
|
|
||||||
})
|
|
||||||
|
|
||||||
return gin.H{
|
|
||||||
"Islands": islands,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
func (f *FinderApplication) RenderPublicContextMenu(context string, filePath string, data string) gin.H {
|
func (f *FinderApplication) RenderPublicContextMenu(context string, filePath string, data string) gin.H {
|
||||||
islands := [][]wde.ContexMenuRow{}
|
islands := [][]wde.ContexMenuRow{}
|
||||||
islands = append(islands, []wde.ContexMenuRow{})
|
islands = append(islands, []wde.ContexMenuRow{})
|
||||||
|
|
||||||
|
//TODO: Links read as source files in props info
|
||||||
islands = append(islands, []wde.ContexMenuRow{
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
{Label: "Get Info", Action: "getInfo"},
|
{Label: "Get Info", Action: "getInfo"},
|
||||||
})
|
})
|
||||||
@ -93,54 +58,12 @@ func (f *FinderApplication) RenderPublicContextMenu(context string, filePath str
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (f *FinderApplication) RenderProps(filePath string) (gin.H, error) {
|
func (f *FinderApplication) RenderProps(filePath string) (gin.H, error) {
|
||||||
// file, err := f.fs.NewReadDeprecated(filePath)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
fileHeader, err := f.fs.Read(filePath, nil)
|
fileHeader, err := f.fs.Read(filePath, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return gin.H{
|
return gin.H{
|
||||||
// "fileId": fileHeader.MongoId,
|
|
||||||
// "fileDataId": fileHeader.Data,
|
|
||||||
"file": fileHeader,
|
"file": fileHeader,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// func (f *FinderApplication) Routes(routes *gin.RouterGroup) {
|
|
||||||
// routes.GET("render", func(ctx *gin.Context) {
|
|
||||||
// isMobileParam := ctx.Query("isMobile")
|
|
||||||
// isMobile := isMobileParam == "true"
|
|
||||||
// admin := true
|
|
||||||
// if isMobile {
|
|
||||||
// ctx.HTML(http.StatusOK, "finder/mobile-app.tmpl", f.Render(isMobile))
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// if admin {
|
|
||||||
// ctx.HTML(http.StatusOK, "finder/admin-app.tmpl", f.Render(isMobile))
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// ctx.HTML(http.StatusOK, "finder/app.tmpl", f.Render(isMobile))
|
|
||||||
|
|
||||||
// })
|
|
||||||
// routes.GET("renderMobileDesktop", func(ctx *gin.Context) {
|
|
||||||
// ctx.HTML(http.StatusOK, "finder/mobile-desktop.tmpl", gin.H{})
|
|
||||||
// })
|
|
||||||
// routes.GET("renderDesktop", func(ctx *gin.Context) {
|
|
||||||
// path := ctx.Query("path")
|
|
||||||
// if path == "" {
|
|
||||||
// ctx.JSON(http.StatusBadRequest, "no path provided")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// ctx.HTML(http.StatusOK, "finder/desktop.tmpl", gin.H{})
|
|
||||||
// })
|
|
||||||
|
|
||||||
// routes.GET("contextMenu", func(ctx *gin.Context) {
|
|
||||||
// context := ctx.Query("context")
|
|
||||||
// data := ctx.Query("data")
|
|
||||||
// ginH := f.RenderContextMenu(context, data)
|
|
||||||
// ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH)
|
|
||||||
// })
|
|
||||||
// }
|
|
||||||
|
@ -2,7 +2,10 @@ package finder
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"personalwebsite/apps"
|
"personalwebsite/apps"
|
||||||
|
"personalwebsite/wde"
|
||||||
"personalwebsite/webfilesystem"
|
"personalwebsite/webfilesystem"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
type FinderAdminApp struct {
|
type FinderAdminApp struct {
|
||||||
@ -20,3 +23,46 @@ func NewFinderAdminApp(webfs *webfilesystem.WebFileSystem) FinderAdminApp {
|
|||||||
func (f *FinderAdminApp) RenderWindow() {
|
func (f *FinderAdminApp) RenderWindow() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func (f *FinderApplication) RenderPrivateContextMenu(context string, filePath string, data string) gin.H {
|
||||||
|
islands := [][]wde.ContexMenuRow{}
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{})
|
||||||
|
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
|
{Label: "Get Info", Action: "getInfo"},
|
||||||
|
})
|
||||||
|
|
||||||
|
if context == "FileTileView" {
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
|
{Label: "New Directory", Action: "createDir"},
|
||||||
|
})
|
||||||
|
return gin.H{
|
||||||
|
"Islands": islands,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
|
{Label: "Create path link", Action: "createPathLink"},
|
||||||
|
})
|
||||||
|
|
||||||
|
switch context {
|
||||||
|
case "directory":
|
||||||
|
if f.fs.GetExtension(filePath) == "app" {
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
|
{Label: "Open as Directory", Action: "openAsDir"},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
|
{Label: "temp Menu 1", Action: ""},
|
||||||
|
{Label: "temp Menu 2", Action: ""},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
islands = append(islands, []wde.ContexMenuRow{
|
||||||
|
{Label: "Delete File", Action: "deleteFile"},
|
||||||
|
})
|
||||||
|
|
||||||
|
return gin.H{
|
||||||
|
"Islands": islands,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -26,17 +26,12 @@ func (f *FinderApplication) PublicRoutes(routes *gin.RouterGroup) {
|
|||||||
|
|
||||||
routes.GET("contextMenu", func(ctx *gin.Context) {
|
routes.GET("contextMenu", func(ctx *gin.Context) {
|
||||||
context := ctx.Query("context")
|
context := ctx.Query("context")
|
||||||
// if context == "" {
|
|
||||||
// ctx.Status(http.StatusBadRequest)
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
filePath := ctx.Query("path")
|
filePath := ctx.Query("path")
|
||||||
if filePath == "" {
|
if filePath == "" {
|
||||||
ctx.Status(http.StatusBadRequest)
|
ctx.Status(http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := ctx.Query("data")
|
data := ctx.Query("data")
|
||||||
// ginH := f.RenderPrivateContextMenu(context, filePath, data)
|
|
||||||
ginH := f.RenderPublicContextMenu(context, filePath, data)
|
ginH := f.RenderPublicContextMenu(context, filePath, data)
|
||||||
ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH)
|
ctx.HTML(http.StatusOK, "wde-widgets/context-menu.tmpl", ginH)
|
||||||
})
|
})
|
||||||
|
@ -161,28 +161,40 @@ class FinderWindow{
|
|||||||
* @param {MouseEvent} event
|
* @param {MouseEvent} event
|
||||||
*/
|
*/
|
||||||
Click(event){
|
Click(event){
|
||||||
let fileType = event.target.getAttribute("fileType")
|
this.OpenFile(this.curPath, event.target.getAttribute("name"), event.target.getAttribute("filetype"))
|
||||||
let fileName = event.target.getAttribute("name")
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} filePath
|
||||||
|
*/
|
||||||
|
async OpenFile(parentPath, fileName, fileType){
|
||||||
|
console.log(parentPath, fileName, fileType)
|
||||||
|
// const splittedPath = filePath.split("/")
|
||||||
|
// const fileName = splittedPath[splittedPath.length - 1]
|
||||||
const fileExtension = fileName.split(".")[fileName.split(".").length - 1] //FIXME
|
const fileExtension = fileName.split(".")[fileName.split(".").length - 1] //FIXME
|
||||||
|
|
||||||
switch (true) {
|
switch (true) {
|
||||||
case fileType == "objectlink":
|
case fileType == "objectlink":
|
||||||
WebDesktopEnvironment.Alert("Links not supported yet")
|
WebDesktopEnvironment.Alert("Links not supported yet")
|
||||||
break
|
break
|
||||||
|
case fileType == "pathlink":
|
||||||
|
let res = await WebFS.ReadPathLink(`${parentPath}/${fileName}`)
|
||||||
|
console.log(res)
|
||||||
|
this.OpenFile(res.parentPath, res.name, res.filetype)
|
||||||
|
break
|
||||||
case fileExtension == "app":
|
case fileExtension == "app":
|
||||||
WebDesktopEnvironment.Open(`${this.curPath}/${fileName}`, [])
|
WebDesktopEnvironment.Open(`${parentPath}/${fileName}`, [])
|
||||||
break
|
break
|
||||||
case fileType == "directory":
|
case fileType == "directory":
|
||||||
WebDesktopEnvironment.Open(`/Applications/Finder.app`, [`${this.curPath}/${fileName}`])
|
WebDesktopEnvironment.Open(`/Applications/Finder.app`, [`${parentPath}/${fileName}`])
|
||||||
break
|
break
|
||||||
case fileExtension == "blog":
|
case fileExtension == "blog":
|
||||||
WebDesktopEnvironment.Open("/Applications/BlogViewer.app", [`${this.curPath}/${fileName}`])
|
WebDesktopEnvironment.Open("/Applications/BlogViewer.app", [`${parentPath}/${fileName}`])
|
||||||
break
|
break
|
||||||
case fileExtension == "jpeg" | fileExtension == "png":
|
case fileExtension == "jpeg" | fileExtension == "png":
|
||||||
WebDesktopEnvironment.Open("img-viewer", [this.curPath + "/" + fileName])
|
WebDesktopEnvironment.Open("img-viewer", [`${parentPath}/${fileName}`])
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// console.log("Unsupported file type")
|
|
||||||
WebDesktopEnvironment.Alert("Unsupported file type")
|
WebDesktopEnvironment.Alert("Unsupported file type")
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -245,6 +257,12 @@ class FinderWindow{
|
|||||||
if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks??
|
if (event.target.classList.contains("Row")){ //TODO add uuid id to rows to more accurate checks??
|
||||||
let res = false
|
let res = false
|
||||||
switch (event.target.children[0].getAttribute("action")) {
|
switch (event.target.children[0].getAttribute("action")) {
|
||||||
|
case "createPathLink":
|
||||||
|
res = await WebFS.CreatePathLink(`${this.curPath}/${fileName}`, `${this.curPath}/Link ${fileName}` )
|
||||||
|
if (res){
|
||||||
|
this.ReRenderDir()
|
||||||
|
}
|
||||||
|
break
|
||||||
case "createDir":
|
case "createDir":
|
||||||
res = await WebFS.CreateDirectory(`${this.curPath}`)
|
res = await WebFS.CreateDirectory(`${this.curPath}`)
|
||||||
console.log(res)
|
console.log(res)
|
||||||
|
@ -272,7 +272,7 @@ class WebFS{
|
|||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
path: `${path}/New Directory`
|
path: `${path}/New Directory`
|
||||||
})
|
})
|
||||||
const response = await fetch(`/fs/createDir?` + params)
|
const response = await fetch(`/system/fs/createDir?` + params)
|
||||||
if (response.status != 200){
|
if (response.status != 200){
|
||||||
WebDesktopEnvironment.Alert("DIRCTORY CREATION ERROR") //TODO
|
WebDesktopEnvironment.Alert("DIRCTORY CREATION ERROR") //TODO
|
||||||
return false
|
return false
|
||||||
@ -288,7 +288,7 @@ class WebFS{
|
|||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
path: path
|
path: path
|
||||||
})
|
})
|
||||||
const response = await fetch(`/fs/delete?` + params)
|
const response = await fetch(`/system/fs/delete?` + params)
|
||||||
if (response.status != 200){
|
if (response.status != 200){
|
||||||
WebDesktopEnvironment.Alert("DELETE ERROR") //TODO
|
WebDesktopEnvironment.Alert("DELETE ERROR") //TODO
|
||||||
return false
|
return false
|
||||||
@ -305,11 +305,62 @@ class WebFS{
|
|||||||
sourcePath: sourcePath,
|
sourcePath: sourcePath,
|
||||||
targetPath: targetPath
|
targetPath: targetPath
|
||||||
})
|
})
|
||||||
const response = await fetch(`/fs/move?` + params)
|
const response = await fetch(`/system/fs/move?` + params)
|
||||||
if (response.status != 200){
|
if (response.status != 200){
|
||||||
// WebDesktopEnvironment.Alert("Move ERROR") //TODO
|
// WebDesktopEnvironment.Alert("Move ERROR") //TODO
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} linkPath
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
static async ReadObjectLink(linkPath){
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
linkPath: linkPath,
|
||||||
|
})
|
||||||
|
const response = await fetch(`/system/fs/readObjectLink?` + params)
|
||||||
|
if (response.status != 200){
|
||||||
|
WebDesktopEnvironment.Alert("TODO") //TODO
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
const path = await response.text()
|
||||||
|
//TODO Validate
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} sourcePath
|
||||||
|
* @param {string} linkPath
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
static async CreatePathLink(sourcePath, linkPath){
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
sourcePath: sourcePath,
|
||||||
|
linkPath: linkPath,
|
||||||
|
})
|
||||||
|
const response = await fetch(`/system/fs/createPathLink?` + params)
|
||||||
|
return response.status == 200
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} linkPath
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
static async ReadPathLink(linkPath){
|
||||||
|
const params = new URLSearchParams({
|
||||||
|
linkPath: linkPath,
|
||||||
|
})
|
||||||
|
const response = await fetch(`/system/fs/readPathLink?` + params)
|
||||||
|
if (response.status != 200){
|
||||||
|
WebDesktopEnvironment.Alert("TODO") //TODO
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
// console.log(response)
|
||||||
|
const file = await response.json()
|
||||||
|
//TODO Validate
|
||||||
|
return file
|
||||||
|
}
|
||||||
}
|
}
|
@ -80,10 +80,10 @@ func PublicRoutes(webfs *webfilesystem.WebFileSystem, webde *wde.WDE, appsStorag
|
|||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// fsGroup := systemGroup.Group("fs")
|
fsGroup := systemGroup.Group("fs")
|
||||||
// {
|
{
|
||||||
// webfs.PublicRoutes(fsGroup)
|
webfs.PublicRoutes(fsGroup)
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
appGroup := router.Group("app")
|
appGroup := router.Group("app")
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
<div>
|
<div>
|
||||||
file id : {{.file.MongoId}}
|
file id : {{.file.MongoId}}
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
file type : {{.file.Type}}
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
file data id : {{.file.Data}}
|
file data id : {{.file.Data}}
|
||||||
</div>
|
</div>
|
||||||
|
24
wde/wde.go
24
wde/wde.go
@ -21,30 +21,6 @@ func NewWDE(webFs *webfilesystem.WebFileSystem) *WDE {
|
|||||||
type FilesWidget struct {
|
type FilesWidget struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated
|
|
||||||
func (w *WDE) Render(path string) (gin.H, error) {
|
|
||||||
// list, err := w.fs.NewListDeprecated(path)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
return gin.H{
|
|
||||||
"Name": "Greg Brzezinski",
|
|
||||||
// "Files": list,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Deprecated
|
|
||||||
func (w *WDE) RenderContextMenu() (gin.H, error) {
|
|
||||||
// list, err := w.fs.List(path)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
return gin.H{
|
|
||||||
"Name": "Greg Brzezinski",
|
|
||||||
// "Files": list,
|
|
||||||
}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) {
|
func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) {
|
||||||
list, err := w.fs.ListDir(directory)
|
list, err := w.fs.ListDir(directory)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -8,7 +8,7 @@ func (fs *WebFileSystem) Read(filePath string, fileData interface{}) (*FileHeade
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
fileHeader, err := fs.readFSDocs(fileId, fileData)
|
fileHeader, err := fs.ReadByObjectID(fileId, fileData)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -22,5 +22,19 @@ func (fs *WebFileSystem) ReadByObjectID(fileID primitive.ObjectID, fileData inte
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fileHeader.Type == "objectlink" {
|
||||||
|
objectLinkData := ObjectLinkFileData{}
|
||||||
|
_, err := fs.readFSDocs(fileID, &objectLinkData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fileHeader, err := fs.readFSDocs(objectLinkData.Link_id, fileData)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return fileHeader, nil
|
||||||
|
}
|
||||||
|
|
||||||
return fileHeader, nil
|
return fileHeader, nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) {
|
func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) {
|
||||||
|
fs.PublicRoutes(route)
|
||||||
route.POST("/upload", func(ctx *gin.Context) { //TODO To PUT request
|
route.POST("/upload", func(ctx *gin.Context) { //TODO To PUT request
|
||||||
// fileName := ctx.Query("fileName")
|
// fileName := ctx.Query("fileName")
|
||||||
// if fileName == "" {
|
// if fileName == "" {
|
||||||
@ -188,8 +189,67 @@ func (fs *WebFileSystem) PrivateRoutes(route *gin.RouterGroup) {
|
|||||||
|
|
||||||
ctx.Status(http.StatusOK)
|
ctx.Status(http.StatusOK)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
route.GET("readObjectLink", func(ctx *gin.Context) {
|
||||||
|
linkPath := ctx.Query("linkPath")
|
||||||
|
if linkPath == "" {
|
||||||
|
ctx.Status(http.StatusBadRequest) //TODO
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// file, err := fs.Read(linkPath, nil)
|
||||||
|
|
||||||
|
ctx.Status(http.StatusOK)
|
||||||
|
})
|
||||||
|
|
||||||
|
route.GET("createPathLink", func(ctx *gin.Context) {
|
||||||
|
sourcePath := ctx.Query("sourcePath")
|
||||||
|
if sourcePath == "" {
|
||||||
|
ctx.Status(http.StatusBadRequest) //TODO
|
||||||
|
return
|
||||||
|
}
|
||||||
|
linkPath := ctx.Query("linkPath")
|
||||||
|
if linkPath == "" {
|
||||||
|
ctx.Status(http.StatusBadRequest) //TODO
|
||||||
|
return
|
||||||
|
}
|
||||||
|
_, _, err := fs.CreatePathLink(sourcePath, linkPath)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Status(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.Status(http.StatusOK)
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *WebFileSystem) PublicRoutes(route *gin.RouterGroup) {
|
func (fs *WebFileSystem) PublicRoutes(route *gin.RouterGroup) {
|
||||||
|
route.GET("readPathLink", func(ctx *gin.Context) {
|
||||||
|
linkPath := ctx.Query("linkPath")
|
||||||
|
if linkPath == "" {
|
||||||
|
ctx.Status(http.StatusBadRequest) //TODO
|
||||||
|
return
|
||||||
|
}
|
||||||
|
linkData := PathLinkFileData{}
|
||||||
|
linkHeader, err := fs.Read(linkPath, &linkData)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Status(http.StatusBadRequest) //TODO
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if linkHeader.Type != "pathlink" {
|
||||||
|
ctx.Status(http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
FileHeader, err := fs.Read(linkData.Path, nil)
|
||||||
|
if err != nil {
|
||||||
|
ctx.Status(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.JSON(http.StatusOK, FrontEndFile{
|
||||||
|
Name: FileHeader.Name,
|
||||||
|
Type: FileHeader.Type,
|
||||||
|
ParentPath: fs.GetParentPath(linkData.Path),
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -54,14 +54,15 @@ type ObjectLinkFileData struct {
|
|||||||
Link_id primitive.ObjectID `bson:"link_id" json:"-"`
|
Link_id primitive.ObjectID `bson:"link_id" json:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated
|
type PathLinkFileData struct {
|
||||||
func (fs *WebFileSystem) ReadHeader(fileID primitive.ObjectID) (*FileHeader, error) {
|
MongoId primitive.ObjectID `bson:"_id" json:"-"`
|
||||||
file := &FileHeader{}
|
Path string `bson:"path" json:"path"`
|
||||||
filter := primitive.M{
|
}
|
||||||
"_id": fileID,
|
|
||||||
}
|
type FrontEndFile struct {
|
||||||
err := fs.webfsFilesTable.FindOne(fs.ctx, filter).Decode(file)
|
Name string `json:"name"`
|
||||||
return file, err
|
Type string `json:"filetype"` //TODO: Rename to Type
|
||||||
|
ParentPath string `json:"parentPath"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO To private, get name from path and set it to file struct, force set newObjectID
|
//TODO To private, get name from path and set it to file struct, force set newObjectID
|
||||||
@ -224,12 +225,6 @@ func (fs *WebFileSystem) Remove(filePath string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (fs *WebFileSystem) CreateObjectLink(sourcePath string, linkPath string) error {
|
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)
|
linkSplittedPath := fs.SplitPath(linkPath)
|
||||||
linkFileName := linkSplittedPath[len(linkSplittedPath)-1]
|
linkFileName := linkSplittedPath[len(linkSplittedPath)-1]
|
||||||
|
|
||||||
@ -267,6 +262,36 @@ func (fs *WebFileSystem) CreateObjectLink(sourcePath string, linkPath string) er
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *WebFileSystem) CreatePathLink(sourcePath string, linkPath string) (primitive.ObjectID, primitive.ObjectID, error) {
|
||||||
|
sourceFileHeader, err := fs.Read(sourcePath, nil)
|
||||||
|
if err != nil {
|
||||||
|
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if sourceFileHeader.Type == "pathlink" {
|
||||||
|
return primitive.NilObjectID, primitive.NilObjectID, errors.New("multiplies pathlinks not supported yet") //TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
newLinkHeader := FileHeader{
|
||||||
|
MongoId: primitive.NewObjectID(),
|
||||||
|
Name: sourceFileHeader.Name,
|
||||||
|
Type: "pathlink",
|
||||||
|
Icon: "",
|
||||||
|
Data: primitive.NewObjectID(),
|
||||||
|
}
|
||||||
|
newLinkData := PathLinkFileData{
|
||||||
|
MongoId: primitive.NewObjectID(),
|
||||||
|
Path: sourcePath,
|
||||||
|
}
|
||||||
|
|
||||||
|
headerID, dataID, err := fs.Write(linkPath, &newLinkHeader, newLinkData)
|
||||||
|
if err != nil {
|
||||||
|
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return headerID, dataID, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (fs *WebFileSystem) SplitPath(path string) []string {
|
func (fs *WebFileSystem) SplitPath(path string) []string {
|
||||||
resPath := []string{}
|
resPath := []string{}
|
||||||
splittedPath := strings.Split(path, "/")
|
splittedPath := strings.Split(path, "/")
|
||||||
|
Loading…
Reference in New Issue
Block a user