Compare commits
No commits in common. "b8eda48aa720038247f3f5b86915efd016544e08" and "405f45e788c61f726bec36be065ce759e0ce65e4" have entirely different histories.
b8eda48aa7
...
405f45e788
2
.env
2
.env
@ -1,3 +1,3 @@
|
||||
MONGO_CONNECT=mongodb://localhost:27017
|
||||
DATABASE=personal-website
|
||||
COLLECTION_WEBFS=webfs2
|
||||
COLLECTION_WEBFS=webfs
|
@ -33,19 +33,15 @@ func (b *BlogViewerApplication) GetId() string {
|
||||
}
|
||||
|
||||
func (b *BlogViewerApplication) Route(route *gin.RouterGroup) {
|
||||
route.GET("writeMockBlog", func(ctx *gin.Context) {
|
||||
path := ctx.Query("path")
|
||||
if path == "" {
|
||||
ctx.JSON(http.StatusBadRequest, "no path provided")
|
||||
return
|
||||
}
|
||||
err := b.WriteMock(path)
|
||||
if err != nil {
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, "OK")
|
||||
})
|
||||
// route.GET("writeMockBlog", func(ctx *gin.Context) {
|
||||
// path := ctx.Query("path")
|
||||
// if path == "" {
|
||||
// ctx.JSON(http.StatusBadRequest, "no path provided")
|
||||
// return
|
||||
// }
|
||||
// b.WriteMock(path)
|
||||
// ctx.JSON(http.StatusOK, "OK")
|
||||
// })
|
||||
|
||||
route.GET("render", func(ctx *gin.Context) {
|
||||
isMobileParam := ctx.Query("isMobile")
|
||||
@ -71,46 +67,56 @@ func (b *BlogViewerApplication) Route(route *gin.RouterGroup) {
|
||||
})
|
||||
}
|
||||
|
||||
func (b *BlogViewerApplication) WriteMock(path string) error {
|
||||
blogFileHeader := webfilesystem.FileHeader{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: "blog1.blog",
|
||||
Type: "",
|
||||
Icon: "",
|
||||
Data: [12]byte{},
|
||||
}
|
||||
blogFileData := BlogFileData{
|
||||
Header: "OMG THIS IS BLOG",
|
||||
Blocks: []Block{
|
||||
{
|
||||
Type: "plain-text",
|
||||
Data: []string{
|
||||
"Apoqiwepoqiwepo",
|
||||
".,mas;dakls;d",
|
||||
"q[poqwieqpipoi]",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
// func (b *BlogViewerApplication) WriteMock(path string) {
|
||||
// blogFile := webfilesystem.WebFSFile{
|
||||
// MongoId: primitive.NewObjectID(),
|
||||
// Name: "test-1.blog",
|
||||
// Type: "blog-page",
|
||||
// Data: BlogFileData{
|
||||
// Header: "OMG THIS IS BLOG",
|
||||
// Blocks: []Block{
|
||||
// {
|
||||
// Type: "plain-text",
|
||||
// Data: []string{
|
||||
// "Apoqiwepoqiwepo",
|
||||
// ".,mas;dakls;d",
|
||||
// "q[poqwieqpipoi]",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// err := b.fs.CreateFile(&blogFile, path)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// }
|
||||
// }
|
||||
|
||||
_, _, err := b.fs.Write("/home/user/blog1.blog", &blogFileHeader, blogFileData)
|
||||
func (b *BlogViewerApplication) Render(path string, isMobile bool) (gin.H, error) {
|
||||
file, err := b.fs.NewRead(path)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *BlogViewerApplication) Render(filePath string, isMobile bool) (gin.H, error) {
|
||||
data := BlogFileData{}
|
||||
_, err := b.fs.Read(filePath, &data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blogDataRaw := file.Data.(primitive.D).Map()
|
||||
header := blogDataRaw["header"]
|
||||
blocks := []Block{}
|
||||
|
||||
for _, rawBlock := range blogDataRaw["blocks"].(primitive.A) {
|
||||
lel := rawBlock.(primitive.D).Map()
|
||||
block := Block{
|
||||
Type: lel["type"].(string),
|
||||
Data: []string{},
|
||||
}
|
||||
for _, v := range lel["data"].(primitive.A) {
|
||||
block.Data = append(block.Data, v.(string))
|
||||
}
|
||||
blocks = append(blocks, block)
|
||||
}
|
||||
|
||||
return gin.H{
|
||||
"header": data.Header,
|
||||
"blocks": data.Blocks,
|
||||
"header": header,
|
||||
"blocks": blocks,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
@ -66,13 +66,13 @@ func (f *FinderApplication) RenderContextMenu(context string, data string) gin.H
|
||||
}
|
||||
|
||||
func (f *FinderApplication) RenderProps(filePath string) gin.H {
|
||||
// file, err := f.fs.NewReadDeprecated(filePath)
|
||||
// if err != nil {
|
||||
// return nil
|
||||
// }
|
||||
file, err := f.fs.NewRead(filePath)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return gin.H{
|
||||
// "file": file,
|
||||
"file": file,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
package personalprops
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
websiteapp "personalwebsite/apps"
|
||||
"personalwebsite/libs"
|
||||
"personalwebsite/webfilesystem"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -26,25 +28,12 @@ func NewPersPropsApp(webFs *webfilesystem.WebFileSystem) PersonalPropertiesApp {
|
||||
}
|
||||
|
||||
func (p *PersonalPropertiesApp) Route(route *gin.RouterGroup) {
|
||||
route.GET("writeMock", func(ctx *gin.Context) {
|
||||
err := p.WriteMock()
|
||||
if err != nil {
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
}
|
||||
ctx.Status(http.StatusOK)
|
||||
})
|
||||
route.GET("render", func(ctx *gin.Context) {
|
||||
isMobileParam := ctx.Query("isMobile")
|
||||
isMobile := isMobileParam == "true"
|
||||
filePath := ctx.Query("path")
|
||||
if filePath == "" {
|
||||
ctx.Status(http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
ginH, err := p.Render(filePath)
|
||||
ginH, err := p.Render()
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO
|
||||
return
|
||||
}
|
||||
if isMobile {
|
||||
ctx.HTML(http.StatusOK, "personal-properties/mobile-app.tmpl", ginH)
|
||||
@ -61,65 +50,170 @@ func (p *PersonalPropertiesApp) GetId() string {
|
||||
return p.manifest.AppId
|
||||
}
|
||||
|
||||
func (p *PersonalPropertiesApp) WriteMock() error {
|
||||
fileHeader := webfilesystem.FileHeader{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: "aboutme.props",
|
||||
Type: "personal-properties",
|
||||
Icon: "",
|
||||
}
|
||||
fileData := PropertiesFileData{
|
||||
Header: HeaderIsland{
|
||||
Name: "Test Name",
|
||||
IconPath: "test icon path",
|
||||
Info1: "Info1",
|
||||
Info2: "Info2",
|
||||
},
|
||||
Props: []PropIsland{
|
||||
{
|
||||
Header: "Test Prop Header",
|
||||
Props: []PropElement{
|
||||
{
|
||||
Key: "Test key",
|
||||
KeyComments: []string{"Test key comment 1", "Test key comment 1"},
|
||||
Values: []string{"test value1", "test value2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Header: "Test Prop Header 2",
|
||||
Props: []PropElement{
|
||||
{
|
||||
Key: "Test key",
|
||||
KeyComments: []string{"Test key comment 1", "Test key comment 1"},
|
||||
Values: []string{"test value1", "test value2"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, _, err := p.fs.Write("/home/user/aboutme.props", &fileHeader, fileData)
|
||||
return err
|
||||
}
|
||||
// func (p *PersonalPropertiesApp) WriteToDb() {
|
||||
// allProps := make([]PropIsland, 0)
|
||||
|
||||
func (p *PersonalPropertiesApp) Render(filePath string) (gin.H, error) {
|
||||
propsData := PropertiesFileData{}
|
||||
_, err := p.fs.Read(filePath, &propsData)
|
||||
// // careerProps := make([]Prop, 0)
|
||||
// expertiseIsland := PropIsland{
|
||||
// Header: "Area Of Expertise",
|
||||
// Props: []PropElement{{
|
||||
// Key: "Programming",
|
||||
// Values: []string{
|
||||
// "Creating tools and plugins for artists",
|
||||
// "Editor and basic gameplay scripting",
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// Key: "Game Art",
|
||||
// Values: []string{
|
||||
// "Professional modeling",
|
||||
// "Complete knowledge in CG render theory",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// eduIsland := PropIsland{
|
||||
// Header: "Education",
|
||||
// Props: []PropElement{
|
||||
// {
|
||||
// Key: "Gymnasium 526",
|
||||
// KeyComments: []string{"2005-2015"},
|
||||
// Values: []string{"Extended natural sciences course", "Additional C++, media production and computer graphics courses", "Winner of conference “The future of a strong Russia is in high technology” in programming section"},
|
||||
// },
|
||||
// {
|
||||
// Key: "Lyceum 281",
|
||||
// KeyComments: []string{"2015-2016"},
|
||||
// Values: []string{"Extended IT and Physical sciences course"},
|
||||
// },
|
||||
// {
|
||||
// Key: "University",
|
||||
// KeyComments: []string{"2017-2019"},
|
||||
// Values: []string{"Faculty: Info-communication Networks and Systems", "Specialty: Information Security"},
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// careerProps := PropIsland{
|
||||
// Header: "Career",
|
||||
// Props: []PropElement{
|
||||
// {
|
||||
// Key: "VR lab assistant",
|
||||
// KeyComments: []string{"Academy of Digital Technologies", "2019-2020"},
|
||||
// Values: []string{"Teaching lessons for students in Unreal Engine 4, Unity and Blender editor courses", "Training students for World Skills Russia"},
|
||||
// },
|
||||
// {
|
||||
// Key: "3d artist",
|
||||
// KeyComments: []string{"Space Time VR", "2020-2020"},
|
||||
// Values: []string{"Creating 3d assets for VR game"},
|
||||
// },
|
||||
// {
|
||||
// Key: "Jr. Techartist",
|
||||
// KeyComments: []string{"MP Games"},
|
||||
// Values: []string{"Game content integration and production", "Shader coding", "Optimization asset production in artists pipeline"},
|
||||
// },
|
||||
// {
|
||||
// Key: "Techartist",
|
||||
// Values: []string{"Game content optimization and production", "Profiling and debugging render pipeline", "Creating in-house tools for pipeline software", "Working process pipeline integration and maintenance", "Linux servers administration"},
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
// volunteerProps := PropIsland{
|
||||
// Header: "Volunteer Experience",
|
||||
// Props: []PropElement{
|
||||
// {
|
||||
// Key: "Metrostroi Mod",
|
||||
// Values: []string{
|
||||
// "Help unite fragmented community on one social platform",
|
||||
// "Worked on social elements of official site, create ranking",
|
||||
// "Took a part on creating ranking system for players",
|
||||
// "Creating models and maps for Steam Workshop"},
|
||||
// },
|
||||
// {
|
||||
// Key: "Age of Silence",
|
||||
// Values: []string{
|
||||
// "Start as tech-artist, create naming system in big ue4 project",
|
||||
// "Promoted to chief of 3d Department",
|
||||
// "Project win Unreal Day 2019",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
|
||||
// allProps = append(allProps, expertiseIsland, careerProps, eduIsland, volunteerProps)
|
||||
// file := webfilesystem.WebFSFile{
|
||||
// MongoId: primitive.NewObjectID(),
|
||||
// Name: "personal.props",
|
||||
// Type: "props",
|
||||
// Data: PropertiesFile{
|
||||
// Props: allProps,
|
||||
// },
|
||||
// }
|
||||
// err := p.fs.CreateFile(&file, "/home/user/")
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// } else {
|
||||
// println("Ok")
|
||||
// }
|
||||
// }
|
||||
|
||||
func (p *PersonalPropertiesApp) Render() (gin.H, error) {
|
||||
props, err := p.fs.NewRead("/home/user/personal.props")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if props.Data == nil || props.Type != "props" {
|
||||
return nil, errors.New("bad file")
|
||||
}
|
||||
headerProps := props.Data.(primitive.D).Map()["headerprops"].(primitive.D).Map()
|
||||
// file, err := p.fs.Read(headerProps["icon"].(string))
|
||||
if err != nil {
|
||||
//TODO err catch
|
||||
}
|
||||
|
||||
// data, err := wde.ReadImage(file)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
hIsland := HeaderIsland{
|
||||
Name: headerProps["name"].(string),
|
||||
// Icon: data,
|
||||
Info1: "LLL",
|
||||
Info2: "QQQ",
|
||||
}
|
||||
|
||||
allProps := make([]PropIsland, 0)
|
||||
|
||||
for _, v := range props.Data.(primitive.D).Map()["props"].(primitive.A) {
|
||||
island := PropIsland{}
|
||||
island.Header = v.(primitive.D).Map()["header"].(string)
|
||||
for _, prop := range v.(primitive.D).Map()["props"].(primitive.A) {
|
||||
elem := PropElement{
|
||||
Key: prop.(primitive.D).Map()["key"].(string),
|
||||
}
|
||||
if prop.(primitive.D).Map()["keycomments"] != nil {
|
||||
for _, keyComments := range prop.(primitive.D).Map()["keycomments"].(primitive.A) {
|
||||
elem.KeyComments = append(elem.KeyComments, keyComments.(string))
|
||||
}
|
||||
}
|
||||
for _, elemValues := range prop.(primitive.D).Map()["values"].(primitive.A) {
|
||||
elem.Values = append(elem.Values, elemValues.(string))
|
||||
}
|
||||
island.Props = append(island.Props, elem)
|
||||
}
|
||||
allProps = append(allProps, island)
|
||||
}
|
||||
|
||||
return gin.H{
|
||||
"headerProps": propsData.Header,
|
||||
"allprops": propsData.Props,
|
||||
"headerProps": hIsland,
|
||||
"allprops": allProps,
|
||||
}, nil
|
||||
}
|
||||
|
||||
type HeaderIsland struct {
|
||||
Name string `bson:"name"`
|
||||
IconPath string `bson:"iconpath"`
|
||||
Info1 string `bson:"info1"`
|
||||
Info2 string `bson:"info2"`
|
||||
Name string
|
||||
Icon *libs.Base64Img
|
||||
Info1 string
|
||||
Info2 string
|
||||
}
|
||||
|
||||
type PropElement struct {
|
||||
@ -133,7 +227,6 @@ type PropIsland struct {
|
||||
Props []PropElement
|
||||
}
|
||||
|
||||
type PropertiesFileData struct {
|
||||
Header HeaderIsland `bson:"header"`
|
||||
Props []PropIsland `bson:"props"`
|
||||
type PropertiesFile struct {
|
||||
Props []PropIsland `bson:"props"`
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
package libs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"personalwebsite/webfilesystem"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type ImagLib struct {
|
||||
@ -17,26 +19,40 @@ func NewImgLib(webfs *webfilesystem.WebFileSystem) *ImagLib {
|
||||
}
|
||||
}
|
||||
|
||||
func ReadImage(img *webfilesystem.WebFSFile) (*Img, error) {
|
||||
data, ok := img.Data.(primitive.D).Map()["srcdata"]
|
||||
if !ok {
|
||||
return nil, errors.New("error in file decoding")
|
||||
}
|
||||
bin := data.(primitive.Binary).Data
|
||||
|
||||
min32Data, ok := img.Data.(primitive.D).Map()["min32data"]
|
||||
if !ok {
|
||||
return nil, errors.New("error in file decoding")
|
||||
}
|
||||
min32Bin := min32Data.(primitive.Binary).Data
|
||||
return &Img{
|
||||
// Header: header,
|
||||
Data: bin,
|
||||
Miniature32: min32Bin,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (l *ImagLib) Route(route *gin.RouterGroup) {
|
||||
route.GET("get", func(ctx *gin.Context) {
|
||||
path := ctx.Query("path")
|
||||
if path == "" {
|
||||
ctx.String(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
|
||||
imgData := Img{}
|
||||
_, err := l.fs.Read(path, &imgData)
|
||||
file, err := l.fs.NewRead(path)
|
||||
if err != nil {
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
return
|
||||
ctx.String(http.StatusInternalServerError, "TODO") //TODO
|
||||
}
|
||||
// _, err = l.fs.readFSDocs(fileId, &imgData)
|
||||
// if err != nil {
|
||||
// ctx.Status(http.StatusInternalServerError)
|
||||
// }
|
||||
data := file.Data.(primitive.Binary)
|
||||
|
||||
ctx.Data(http.StatusOK, "image/jpeg", imgData.Bin)
|
||||
ctx.Data(http.StatusOK, "image/jpeg", data.Data)
|
||||
})
|
||||
|
||||
}
|
||||
@ -60,7 +76,7 @@ type Base64Img struct {
|
||||
}
|
||||
|
||||
type Img struct {
|
||||
Header string `bson:"header"`
|
||||
Bin []byte `bson:"bin"`
|
||||
// BinMin32 []byte `bson:"binmin32"`
|
||||
Header string `bson:"header"`
|
||||
Data []byte `bson:"srcdata"`
|
||||
Miniature32 []byte `bson:"min32data"`
|
||||
}
|
||||
|
@ -15,17 +15,17 @@
|
||||
|
||||
.blog-viewer .header-h1{
|
||||
font-size:x-large;
|
||||
padding-bottom: 10px;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.blog-viewer .header-h2{
|
||||
font-size:large;
|
||||
padding-bottom: 6px;
|
||||
padding: 6px;
|
||||
}
|
||||
|
||||
.blog-viewer .header-h3{
|
||||
font-size:larger;
|
||||
padding-bottom: 2px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.blog-viewer .plain-text{
|
||||
|
@ -36,9 +36,9 @@ class Finder{
|
||||
)
|
||||
this.OpenDir(this.path)
|
||||
|
||||
newWindow.querySelector("#RootButton").addEventListener('click', () =>{
|
||||
this.OpenDir('/')
|
||||
})
|
||||
// newWindow.querySelector("#BackButton").addEventListener('click', () =>{
|
||||
// this.OpenPreviousDir()
|
||||
// })
|
||||
|
||||
// newWindow.querySelector("#HomeButton").addEventListener('click', () =>{
|
||||
// this.OpenDir(this.homePath)
|
||||
@ -68,16 +68,16 @@ class Finder{
|
||||
|
||||
FileUploading(filesList){
|
||||
let formData = new FormData()
|
||||
console.log(this.path)
|
||||
// console.log(filesList)
|
||||
for (let i = 0; i < filesList.length; i++) {
|
||||
const element = filesList[i];
|
||||
formData.append("file", element.getAsFile())
|
||||
// console.log(formData)
|
||||
console.log(formData)
|
||||
}
|
||||
// console.log(formData)
|
||||
// formData.append("photo", photo);
|
||||
fetch('/fs/upload/?' + new URLSearchParams({
|
||||
parentPath: this.path,
|
||||
path: '/home/user/',
|
||||
}),
|
||||
{
|
||||
method: "POST",
|
||||
@ -125,16 +125,15 @@ class Finder{
|
||||
* @param {string} path
|
||||
*/
|
||||
OpenDir(path){
|
||||
this.path = path
|
||||
this.fileView.OpenFolder(path)
|
||||
this.fileView.OpenFolder(this.path)
|
||||
}
|
||||
|
||||
|
||||
// /**
|
||||
// */
|
||||
// OpenNewDir(){
|
||||
// WebDesktopEnvironment.Open("finder", [this.path])
|
||||
// }
|
||||
/**
|
||||
*/
|
||||
OpenNewDir(){
|
||||
WebDesktopEnvironment.Open("finder", [this.path])
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {MouseEvent} event
|
||||
|
@ -22,23 +22,7 @@
|
||||
width: 0;
|
||||
height: 0;
|
||||
} */
|
||||
.PersPropsContent{
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
/* Auto layout */
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
padding: 0px;
|
||||
}
|
||||
|
||||
.PersPropsContent .PropsView{
|
||||
/* background-color: rebeccapurple; */
|
||||
width: 100%;
|
||||
height: auto;
|
||||
}
|
||||
.PropertiesList{
|
||||
/* width: 100%;
|
||||
height: auto; */
|
||||
@ -57,7 +41,7 @@
|
||||
}
|
||||
|
||||
|
||||
.PropertiesList .ShortBio{
|
||||
.Personal-properties-bio{
|
||||
/* width: 100%;
|
||||
height: auto; */
|
||||
/* margin-right: -20px; */
|
||||
@ -77,7 +61,9 @@
|
||||
gap:15px;
|
||||
}
|
||||
|
||||
.ShortBio .Text{
|
||||
|
||||
|
||||
.Personal-properties-textbio{
|
||||
/* width: 100%;
|
||||
height: auto; */
|
||||
|
||||
@ -95,14 +81,8 @@
|
||||
gap:1px;
|
||||
}
|
||||
|
||||
.ShortBio .Name{
|
||||
font-family: "Virtue";
|
||||
/* FIXME */
|
||||
letter-spacing: 0.35px;
|
||||
}
|
||||
|
||||
|
||||
.PropertiesList .Island{
|
||||
.Personal-properties-prop{
|
||||
width: 100%;
|
||||
height: auto;
|
||||
border: 1px solid #888888;
|
||||
@ -117,9 +97,11 @@
|
||||
gap:1px; */
|
||||
}
|
||||
|
||||
.Island .Title {
|
||||
|
||||
|
||||
|
||||
.Personal-properties-prop-title{
|
||||
font-family: "Virtue";
|
||||
/* FIXME */
|
||||
letter-spacing: 0.35px;
|
||||
position:relative;
|
||||
display: inline-block;
|
||||
@ -129,11 +111,7 @@
|
||||
top: -9px;
|
||||
}
|
||||
|
||||
.Focused .Island .Title{
|
||||
background-color: #CCCCCC;
|
||||
}
|
||||
|
||||
.Island .Content{
|
||||
.Personal-properties-prop-content{
|
||||
width: 100%;
|
||||
/* top: 0px; */
|
||||
/* Auto layout */
|
||||
@ -144,7 +122,7 @@
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.Island .Row{
|
||||
.Personal-properties-prop-row{
|
||||
margin-left: 12px;
|
||||
margin-right: 12px;
|
||||
/* Auto layout */
|
||||
@ -154,7 +132,7 @@
|
||||
padding: 0px;
|
||||
gap: 5px;
|
||||
}
|
||||
.Island .Key{
|
||||
.Personal-properties-prop-key{
|
||||
position: relative;
|
||||
font-family: "Virtue";
|
||||
font-size: 11px;
|
||||
@ -167,7 +145,7 @@
|
||||
/* font-weight: bold; */
|
||||
}
|
||||
|
||||
.Island .KeyComment{
|
||||
.Personal-properties-prop-key-comments{
|
||||
/* color: rgb(129, 129, 129); TODO*/
|
||||
color: #646464;
|
||||
font-size: 9px;
|
||||
@ -176,8 +154,7 @@
|
||||
white-space:normal;
|
||||
/* filter: drop-shadow(-.5px -.5px 0px #616161); */
|
||||
}
|
||||
|
||||
.Island .Values{
|
||||
.Personal-properties-prop-values{
|
||||
width: 55%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
@ -187,7 +164,7 @@
|
||||
|
||||
}
|
||||
|
||||
.Values .Value{
|
||||
.Personal-properties-prop-value{
|
||||
/* width: 55%; */
|
||||
|
||||
}
|
@ -13,7 +13,6 @@ class PersonalProperties{
|
||||
NewWindow(path){
|
||||
fetch(`${window.location.origin}/application/personal-properties/render?`+ new URLSearchParams({
|
||||
isMobile: WebDesktopEnvironment.isMobile,
|
||||
path: path
|
||||
}))
|
||||
.then((response) => response.text())
|
||||
.then((html) => {
|
||||
@ -23,7 +22,7 @@ class PersonalProperties{
|
||||
|
||||
newWindow.innerHTML = html
|
||||
|
||||
let scrollBar = new WdeScrollBar(newWindow.querySelector('.ScrollBarScrollElement'), newWindow.querySelector('.PropsView'))
|
||||
let scrollBar = new WdeScrollBar(newWindow.querySelector('.ScrollBarScrollElement'), newWindow.querySelector('.ScrollContent'))
|
||||
|
||||
newWindow.querySelector("#closeWindowButton").addEventListener('click', () => {
|
||||
console.log("qewqweqweqweqwe")
|
||||
|
@ -4,9 +4,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// console.log(window.screen.width)
|
||||
wde = new WebDesktopEnvironment
|
||||
if (!WebDesktopEnvironment.isMobile){
|
||||
// WebDesktopEnvironment.Open("finder", ["/home/user"])
|
||||
// WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog1.blog"])
|
||||
WebDesktopEnvironment.Open("personal-properties", ["/home/user/aboutme.props"])
|
||||
WebDesktopEnvironment.Open("finder", ["/home/user"])
|
||||
// WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
|
||||
// WebDesktopEnvironment.Open("personal-properties", ["kek"])
|
||||
} else {
|
||||
WebDesktopEnvironment.Open("blog-viewer", ["/home/user/blog/test-1.blog"])
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
<div id="ContentBorder" class="ContentBorder AdjectiveElement">
|
||||
<div class="FinderContent">
|
||||
<div class="ToolBar ConvexElement">
|
||||
<button id="RootButton">/</button>
|
||||
<button id="BackButton">Back</button>
|
||||
<button id="HomeButton">Home</button>
|
||||
</div>
|
||||
<div class="FinderFileView">
|
||||
|
@ -7,37 +7,36 @@
|
||||
</div>
|
||||
<div id="Drag" class="VisualDragArea"></div>
|
||||
</div>
|
||||
<div class="ContentBorder AdjectiveElement">
|
||||
<div class="PersPropsContent">
|
||||
<div class="PropsView">
|
||||
<div class="PropertiesList">
|
||||
<div class="ShortBio">
|
||||
<img src="/system/libs/img/get?path={{ .headerProps.IconPath }}" alt="My Photo" style="width: 48px;height: 48px;">
|
||||
<div class="Text">
|
||||
<div class="Name">{{ .headerProps.Name }}</div>
|
||||
<div>{{ .headerProps.Info1 }}</div>
|
||||
<div>{{ .headerProps.Info2 }}</div>
|
||||
</div>
|
||||
<div class="ContentBorder">
|
||||
<div class="ScrollContent">
|
||||
<div class="PropertiesList">
|
||||
<div class="Personal-properties-bio">
|
||||
<img src="data:{{ .headerProps.Icon.Header }},{{ .headerProps.Icon.Base64 }}" alt="My Photo" style="width: 48px;height: 48px;">
|
||||
<div class="Personal-properties-textbio">
|
||||
<div>{{ .headerProps.Name }}</div>
|
||||
<div>{{ .headerProps.Info1 }}</div>
|
||||
<div>{{ .headerProps.Info2 }}</div>
|
||||
</div>
|
||||
{{ range $propIsland := .allprops }}
|
||||
<div class="Island">
|
||||
<div class="Title">
|
||||
</div>
|
||||
{{ range $propIsland := .allprops }}
|
||||
<div id="prop" class="Personal-properties-prop">
|
||||
<div class="Personal-properties-prop-title">
|
||||
{{$propIsland.Header}}:
|
||||
</div>
|
||||
<div class="Content">
|
||||
<div class="Personal-properties-prop-content">
|
||||
{{range $prop := $propIsland.Props}}
|
||||
<div class="Row">
|
||||
<div class="Key">
|
||||
<div class="Personal-properties-prop-row">
|
||||
<div class="Personal-properties-prop-key">
|
||||
{{$prop.Key}}:
|
||||
{{ range $value := $prop.KeyComments }}
|
||||
<div class="KeyComment">
|
||||
<div class="Personal-properties-prop-key-comments">
|
||||
{{ $value }}
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
<div class="Values">
|
||||
<div class="Personal-properties-prop-values">
|
||||
{{ range $value := $prop.Values }}
|
||||
<div class="Value">
|
||||
<div class="Personal-properties-prop-value">
|
||||
{{ $value }}
|
||||
</div>
|
||||
{{ end }}
|
||||
@ -47,10 +46,9 @@
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{template "wde-widgets/scrollbar.tmpl" .}}
|
||||
</div>
|
||||
{{template "wde-widgets/scrollbar.tmpl" .}}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
|
BIN
test-img/folder.png
(Stored with Git LFS)
BIN
test-img/folder.png
(Stored with Git LFS)
Binary file not shown.
BIN
test-img/ohno.png
(Stored with Git LFS)
BIN
test-img/ohno.png
(Stored with Git LFS)
Binary file not shown.
17
wde/wde.go
17
wde/wde.go
@ -22,13 +22,13 @@ type FilesWidget struct {
|
||||
}
|
||||
|
||||
func (w *WDE) Render(path string) (gin.H, error) {
|
||||
// list, err := w.fs.NewListDeprecated(path)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
list, err := w.fs.NewList(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return gin.H{
|
||||
"Name": "Greg Brzezinski",
|
||||
// "Files": list,
|
||||
"Name": "Greg Brzezinski",
|
||||
"Files": list,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -44,11 +44,10 @@ func (w *WDE) RenderContextMenu() (gin.H, error) {
|
||||
}
|
||||
|
||||
func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) {
|
||||
list, err := w.fs.ListDir(directory)
|
||||
list, err := w.fs.NewList(directory)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, file := range list {
|
||||
switch file.Type {
|
||||
case "directory":
|
||||
@ -60,7 +59,7 @@ func (w *WDE) RenderFileTileView(directory string, host string) (gin.H, error) {
|
||||
case "jpg":
|
||||
file.Icon = host + "/system/libs/img/get?path=" + path.Join(directory, file.Name) //FIXME
|
||||
default:
|
||||
file.Icon = host + "/system/libs/img/get?path=/wde/icons/macos9/folder.png" //FIXME
|
||||
file.Icon = host + "/system/libs/img/get?path=/wde/icons/macos9/about-me.png" //FIXME
|
||||
}
|
||||
}
|
||||
return gin.H{
|
||||
|
@ -1,136 +1,84 @@
|
||||
package webfilesystem
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"context"
|
||||
"strconv"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
type DirectoryData struct {
|
||||
MongoId primitive.ObjectID `bson:"_id"`
|
||||
Parent primitive.ObjectID `bson:"parent_id"`
|
||||
Children []primitive.ObjectID `bson:"children_id"`
|
||||
Parent primitive.ObjectID `bson:"parent"`
|
||||
Children []primitive.ObjectID `bson:"children"`
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) CreateDirectory(dirPath string) (primitive.ObjectID, primitive.ObjectID, error) {
|
||||
func (fs *WebFileSystem) NewCreateDirectory(dirPath string) (primitive.ObjectID, error) {
|
||||
splittedPath := fs.SplitPath(dirPath)
|
||||
parentPath := fs.GetParentPath(dirPath)
|
||||
|
||||
parentDirId, err := fs.FindFile(parentPath)
|
||||
parentDirRaw, err := fs.NewRead(parentPath)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
|
||||
parentDirHeader, err := fs.readFSDocs(parentDirId, nil)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
}
|
||||
|
||||
newDir := FileHeader{
|
||||
newDir := WebFSFile{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: splittedPath[len(splittedPath)-1],
|
||||
Type: "directory",
|
||||
Icon: "",
|
||||
Data: DirectoryData{
|
||||
Parent: parentDirRaw.MongoId,
|
||||
Children: []primitive.ObjectID{},
|
||||
},
|
||||
Icon: "",
|
||||
}
|
||||
newDirData := DirectoryData{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Parent: parentDirHeader.MongoId,
|
||||
Children: []primitive.ObjectID{},
|
||||
objectId, err := fs.writeMongo(newDir, parentPath)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
|
||||
headerId, dataId, err := fs.writeFileToMongo(&newDir, &newDirData)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
}
|
||||
|
||||
err = fs.AppendChildToDirectory(headerId, parentDirId)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
}
|
||||
return headerId, dataId, nil
|
||||
return objectId, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) AppendChildToDirectory(childId primitive.ObjectID, parentId primitive.ObjectID) error {
|
||||
parentDirData := DirectoryData{}
|
||||
parentDir, err := fs.readFSDocs(parentId, &parentDirData)
|
||||
if err != nil {
|
||||
return err
|
||||
func (fs *WebFileSystem) validateDir(dir *WebFSFile) error {
|
||||
kek := dir.Data.(primitive.D).Map()["children"].(primitive.A)
|
||||
_ = kek
|
||||
|
||||
children := []primitive.ObjectID{}
|
||||
counter := 0
|
||||
for _, v := range kek {
|
||||
_, err := fs.ReadByObjectID(v.(primitive.ObjectID))
|
||||
if err != nil {
|
||||
counter++
|
||||
} else {
|
||||
children = append(children, v.(primitive.ObjectID))
|
||||
}
|
||||
}
|
||||
if counter > 0 {
|
||||
println(dir.Name + " broken iDs: " + strconv.Itoa(counter))
|
||||
_, err := fs.webfsCollection.UpdateByID(context.Background(), dir.MongoId, bson.M{"$set": bson.M{"data.children": children}})
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
//TODO Check for duplicates?
|
||||
parentDirData.Children = append(parentDirData.Children, childId)
|
||||
|
||||
err = fs.UpdateFileData(parentDir, parentDirData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) ListDir(dirPath string) ([]*FileHeader, error) {
|
||||
dirId, err := fs.FindFile(dirPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func castToFile(raw *interface{}) *WebFSFile {
|
||||
var dirPtr interface{} = *raw
|
||||
return dirPtr.(*WebFSFile)
|
||||
}
|
||||
|
||||
func castToDirectoryData(data interface{}) (*DirectoryData, error) {
|
||||
dirData := DirectoryData{}
|
||||
_, err = fs.readFSDocs(dirId, &dirData)
|
||||
err := mapstructure.Decode(data.(primitive.D).Map(), &dirData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// println(dirId.String())
|
||||
// println(dirData.MongoId.String())
|
||||
|
||||
children := []*FileHeader{}
|
||||
for _, childID := range dirData.Children {
|
||||
childFile, err := fs.readFSDocs(childID, nil)
|
||||
if err != nil {
|
||||
// println(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
children = append(children, childFile)
|
||||
|
||||
}
|
||||
return children, nil
|
||||
return &dirData, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) FindFile(filePath string) (primitive.ObjectID, error) {
|
||||
splittedPath := fs.SplitPath(filePath)
|
||||
rootDir, _, err := fs.GetRootDir()
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
// println(rootDir.Name)
|
||||
lastFileID := rootDir.MongoId
|
||||
for _, pathPart := range splittedPath[1:] {
|
||||
// println(pathPart)
|
||||
id, err := fs.findInChildren(pathPart, lastFileID)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
lastFileID = id
|
||||
}
|
||||
return lastFileID, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) findInChildren(fileName string, parentDirId primitive.ObjectID) (primitive.ObjectID, error) {
|
||||
parentDirData := DirectoryData{}
|
||||
_, err := fs.readFSDocs(parentDirId, &parentDirData)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
|
||||
for _, childId := range parentDirData.Children {
|
||||
childFileHeader, err := fs.readFSDocs(childId, nil)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
if childFileHeader.Name == fileName {
|
||||
return childId, nil
|
||||
}
|
||||
}
|
||||
|
||||
return primitive.NilObjectID, errors.New("file not found")
|
||||
}
|
||||
// func List()
|
||||
|
@ -5,13 +5,11 @@ package webfilesystem
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func (fs *WebFileSystem) UploadFile(realFilepath string, parentPath string) error {
|
||||
//TODO check is file exists
|
||||
func (fs *WebFileSystem) UploadFile(realFilepath string, path string) error {
|
||||
file, err := os.ReadFile(realFilepath)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -20,36 +18,57 @@ func (fs *WebFileSystem) UploadFile(realFilepath string, parentPath string) erro
|
||||
fileName := splittedPath[len(splittedPath)-1]
|
||||
extension := fs.GetExtension(fileName)
|
||||
|
||||
newFile2 := FileHeader{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: fileName,
|
||||
Type: "",
|
||||
Icon: "",
|
||||
Data: primitive.NilObjectID,
|
||||
}
|
||||
|
||||
newFileData := BinaryFileData{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Bin: file,
|
||||
}
|
||||
|
||||
filePath := path.Join(parentPath, fileName)
|
||||
|
||||
switch extension {
|
||||
case "jpg":
|
||||
fallthrough
|
||||
case "jpeg":
|
||||
newFile2.Type = "jpeg"
|
||||
_, _, err := fs.Write(filePath, &newFile2, &newFileData)
|
||||
newFile := WebFSFile{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: fileName,
|
||||
Type: "jpeg",
|
||||
Data: file,
|
||||
Icon: "",
|
||||
}
|
||||
err := fs.WriteFile(&newFile, path)
|
||||
return err
|
||||
case "png":
|
||||
newFile2.Type = "png"
|
||||
_, _, err := fs.Write(filePath, &newFile2, &newFileData)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return err
|
||||
newFile := WebFSFile{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: fileName,
|
||||
Type: "png",
|
||||
Data: file,
|
||||
}
|
||||
return nil
|
||||
err := fs.WriteFile(&newFile, path)
|
||||
return err
|
||||
default:
|
||||
return errors.New("this filetype not allowed")
|
||||
}
|
||||
|
||||
}
|
||||
func (fs *WebFileSystem) UploadBinaryFile(file []byte, fileName string, path string) error {
|
||||
extension := fs.GetExtension(fileName)
|
||||
switch extension {
|
||||
case "jpg":
|
||||
fallthrough
|
||||
case "jpeg":
|
||||
newFile := WebFSFile{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: fileName,
|
||||
Type: "jpeg",
|
||||
Data: file,
|
||||
Icon: "",
|
||||
}
|
||||
err := fs.WriteFile(&newFile, path)
|
||||
return err
|
||||
case "png":
|
||||
newFile := WebFSFile{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: fileName,
|
||||
Type: "png",
|
||||
Data: file,
|
||||
}
|
||||
err := fs.WriteFile(&newFile, path)
|
||||
return err
|
||||
default:
|
||||
return errors.New("this filetype not allowed")
|
||||
}
|
||||
|
@ -1,77 +1,94 @@
|
||||
package webfilesystem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func (fs *WebFileSystem) readFSDocs(fileID primitive.ObjectID, fileData interface{}) (*FileHeader, error) {
|
||||
fileHeader := &FileHeader{}
|
||||
filter := primitive.M{
|
||||
"_id": fileID,
|
||||
}
|
||||
err := fs.webfsFilesTable.FindOne(fs.ctx, filter).Decode(fileHeader)
|
||||
type readStruct struct {
|
||||
File interface{}
|
||||
Filter interface{}
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) readMongo(read readStruct) (*interface{}, error) {
|
||||
err := fs.webfsCollection.FindOne(fs.ctx, read.Filter).Decode(read.File)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fileData != nil {
|
||||
filter := primitive.M{
|
||||
"_id": fileHeader.Data,
|
||||
}
|
||||
err := fs.webfsFilesData.FindOne(fs.ctx, filter).Decode(fileData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return fileHeader, nil
|
||||
return &read.File, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) writeFileToMongo(file *FileHeader, data interface{}) (primitive.ObjectID, primitive.ObjectID, error) {
|
||||
resData, err := fs.webfsFilesData.InsertOne(fs.ctx, data)
|
||||
func (fs *WebFileSystem) writeMongo(file WebFSFile, parentPath string) (primitive.ObjectID, error) {
|
||||
//TODO Check file existance
|
||||
parentDir, err := fs.NewRead(parentPath)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
file.Data = resData.InsertedID.(primitive.ObjectID)
|
||||
resHeader, err := fs.webfsFilesTable.InsertOne(fs.ctx, file)
|
||||
res, err := fs.webfsCollection.InsertOne(context.Background(), &file)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
return primitive.NilObjectID, err
|
||||
}
|
||||
return resHeader.InsertedID.(primitive.ObjectID), resData.InsertedID.(primitive.ObjectID), err
|
||||
|
||||
fileId := fs.castInsertId(res)
|
||||
fs.insertFileToDirectory(fileId, parentDir.MongoId)
|
||||
|
||||
return fileId, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) removeFromMongo(fileId primitive.ObjectID) error {
|
||||
return errors.New("todo not implemented yet")
|
||||
func (fs *WebFileSystem) removeMongo(filePath string) error {
|
||||
file, err := fs.NewRead(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if file.MongoId == primitive.NilObjectID {
|
||||
return errors.New("TODO") //TODO
|
||||
}
|
||||
filter := primitive.M{
|
||||
"_id": file.MongoId,
|
||||
}
|
||||
res, err := fs.webfsCollection.DeleteOne(fs.ctx, filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if res.DeletedCount < 1 {
|
||||
return errors.New("no file removed")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) Validate() error {
|
||||
// filter := primitive.D{
|
||||
// {
|
||||
// Key: "type",
|
||||
// Value: "directory",
|
||||
// },
|
||||
// }
|
||||
// cur, err := fs.webfsCollection.Find(context.Background(), filter)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// defer cur.Close(context.Background())
|
||||
filter := primitive.D{
|
||||
{
|
||||
Key: "type",
|
||||
Value: "directory",
|
||||
},
|
||||
}
|
||||
cur, err := fs.webfsCollection.Find(context.Background(), filter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer cur.Close(context.Background())
|
||||
|
||||
// directories := []*WebFSFile{}
|
||||
directories := []*WebFSFile{}
|
||||
|
||||
// for cur.Next(context.Background()) {
|
||||
// dir := &WebFSFile{}
|
||||
for cur.Next(context.Background()) {
|
||||
dir := &WebFSFile{}
|
||||
|
||||
// err = cur.Decode(dir)
|
||||
// if err != nil {
|
||||
// println(err.Error())
|
||||
// return err
|
||||
// }
|
||||
// directories = append(directories, dir)
|
||||
// }
|
||||
err = cur.Decode(dir)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
return err
|
||||
}
|
||||
directories = append(directories, dir)
|
||||
}
|
||||
|
||||
// for _, d := range directories {
|
||||
// fs.validateDir(d)
|
||||
// }
|
||||
for _, d := range directories {
|
||||
fs.validateDir(d)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
56
webfilesystem/newmethods.go
Normal file
56
webfilesystem/newmethods.go
Normal file
@ -0,0 +1,56 @@
|
||||
package webfilesystem
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
)
|
||||
|
||||
func (fs *WebFileSystem) NewRead(filePath string) (*WebFSFile, error) {
|
||||
splittedPath := fs.SplitPath(filePath)
|
||||
read := readStruct{
|
||||
File: &WebFSFile{},
|
||||
Filter: primitive.M{
|
||||
"name": splittedPath[len(splittedPath)-1],
|
||||
},
|
||||
}
|
||||
fileRaw, err := fs.readMongo(read)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
file := castToFile(fileRaw)
|
||||
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) NewList(dirPath string) ([]*WebFSFile, error) {
|
||||
dirFile, err := fs.NewRead(dirPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if dirFile.Type != "directory" {
|
||||
return nil, errors.New("file is not a directory")
|
||||
}
|
||||
|
||||
fileData, err := castToDirectoryData(dirFile.Data)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
files := []*WebFSFile{}
|
||||
for _, child := range fileData.Children {
|
||||
file, err := fs.ReadByObjectID(child)
|
||||
if err != nil {
|
||||
println(err.Error())
|
||||
continue
|
||||
}
|
||||
files = append(files, file)
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) WriteFile(file *WebFSFile, parentPath string) error {
|
||||
fs.writeMongo(*file, parentPath)
|
||||
return errors.New("Not ready yet")
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
package webfilesystem
|
||||
|
||||
func (fs *WebFileSystem) Read(filePath string, fileData interface{}) (*FileHeader, error) {
|
||||
fileId, err := fs.FindFile(filePath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fileHeader, err := fs.readFSDocs(fileId, fileData)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return fileHeader, nil
|
||||
}
|
@ -13,8 +13,8 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
|
||||
// ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
// return
|
||||
// }
|
||||
parentPath := ctx.Query("parentPath")
|
||||
if parentPath == "" {
|
||||
path := ctx.Query("path")
|
||||
if path == "" {
|
||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
@ -32,7 +32,7 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
|
||||
ctx.SaveUploadedFile(file, dst)
|
||||
|
||||
//TODO: Not Save to disk
|
||||
err := fs.UploadFile(dst, parentPath)
|
||||
err := fs.UploadFile(dst, path)
|
||||
if err != nil {
|
||||
ctx.String(http.StatusInternalServerError, "TODO") //TODO
|
||||
return
|
||||
@ -65,14 +65,14 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
|
||||
// ctx.JSON(http.StatusOK, "OK")
|
||||
// })
|
||||
|
||||
route.GET("init", func(ctx *gin.Context) {
|
||||
err := fs.InitFS()
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, err.Error()) //TODO json error struct
|
||||
return
|
||||
}
|
||||
ctx.JSON(http.StatusOK, "Inited")
|
||||
})
|
||||
// route.GET("init", func(ctx *gin.Context) {
|
||||
// err := fs.InitFS()
|
||||
// if err != nil {
|
||||
// ctx.JSON(http.StatusInternalServerError, err.Error()) //TODO json error struct
|
||||
// return
|
||||
// }
|
||||
// ctx.JSON(http.StatusOK, "OK")
|
||||
// })
|
||||
|
||||
route.GET("createDir", func(ctx *gin.Context) {
|
||||
path := ctx.Query("path")
|
||||
@ -81,7 +81,7 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
|
||||
return
|
||||
}
|
||||
|
||||
_, _, err := fs.CreateDirectory(path)
|
||||
_, err := fs.NewCreateDirectory(path)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, err.Error()) //TODO json error struct
|
||||
return
|
||||
@ -97,30 +97,30 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
|
||||
return
|
||||
}
|
||||
|
||||
files, err := fs.ListDir(path)
|
||||
files, err := fs.NewList(path)
|
||||
if err != nil {
|
||||
ctx.String(http.StatusInternalServerError, err.Error()) //TODO json error struct
|
||||
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
|
||||
ctx.JSON(http.StatusOK, &files)
|
||||
})
|
||||
|
||||
// route.GET("read", func(ctx *gin.Context) {
|
||||
// path := ctx.Query("path")
|
||||
// if path == "" {
|
||||
// ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
// return
|
||||
// }
|
||||
route.GET("read", func(ctx *gin.Context) {
|
||||
path := ctx.Query("path")
|
||||
if path == "" {
|
||||
ctx.JSON(http.StatusBadRequest, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
|
||||
// file, err := fs.NewReadDeprecated(path)
|
||||
// if err != nil {
|
||||
// ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
|
||||
// return
|
||||
// }
|
||||
file, err := fs.NewRead(path)
|
||||
if err != nil {
|
||||
ctx.JSON(http.StatusInternalServerError, "TODO") //TODO json error struct
|
||||
return
|
||||
}
|
||||
|
||||
// ctx.JSON(http.StatusOK, &file)
|
||||
// })
|
||||
ctx.JSON(http.StatusOK, &file)
|
||||
})
|
||||
|
||||
route.GET("validate", func(ctx *gin.Context) {
|
||||
err := fs.Validate()
|
||||
@ -138,7 +138,7 @@ func (fs *WebFileSystem) Route(route *gin.RouterGroup) {
|
||||
ctx.Status(http.StatusBadRequest) //TODO
|
||||
return
|
||||
}
|
||||
err := fs.Remove(path)
|
||||
err := fs.Delete(path)
|
||||
if err != nil {
|
||||
ctx.Status(http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -2,9 +2,9 @@ package webfilesystem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@ -12,155 +12,57 @@ import (
|
||||
|
||||
type WebFileSystem struct {
|
||||
webfsCollection *mongo.Collection
|
||||
webfsFilesTable *mongo.Collection
|
||||
webfsFilesData *mongo.Collection
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
func NewWebFileSystem(mongoClient *mongo.Client, dBName string, fsCollectionName string) *WebFileSystem {
|
||||
return &WebFileSystem{
|
||||
webfsCollection: mongoClient.Database(dBName).Collection(fsCollectionName), // TODO Check collection is exist
|
||||
webfsFilesTable: mongoClient.Database(dBName).Collection("webfs-table"), // TODO Check collection is exist, //FIXME
|
||||
webfsFilesData: mongoClient.Database(dBName).Collection("webfs-data"), // TODO Check collection is exist, //FIXME
|
||||
ctx: context.Background(),
|
||||
}
|
||||
}
|
||||
|
||||
type FileHeader struct {
|
||||
MongoId primitive.ObjectID `bson:"_id" json:"-"`
|
||||
Name string `bson:"name" json:"name"`
|
||||
Type string `bson:"type" json:"type"`
|
||||
Icon string `bson:"-" json:"icon"`
|
||||
Data primitive.ObjectID `bson:"data_id" json:"-"`
|
||||
}
|
||||
type BinaryFileData struct {
|
||||
MongoId primitive.ObjectID `bson:"_id" json:"-"`
|
||||
Bin []byte `bson:"bin" json:"-"`
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
func (fs *WebFileSystem) ReadHeader(fileID primitive.ObjectID) (*FileHeader, error) {
|
||||
file := &FileHeader{}
|
||||
filter := primitive.M{
|
||||
"_id": fileID,
|
||||
func (fs *WebFileSystem) ReadByObjectID(objectId primitive.ObjectID) (*WebFSFile, error) {
|
||||
filter := primitive.D{
|
||||
{
|
||||
Key: "_id",
|
||||
Value: objectId,
|
||||
},
|
||||
}
|
||||
err := fs.webfsFilesTable.FindOne(fs.ctx, filter).Decode(file)
|
||||
//TODO to readMongo()
|
||||
file, err := fs.findFileInMongo(filter)
|
||||
return file, err
|
||||
}
|
||||
|
||||
//TODO To private, get name from path and set it to file struct, force set newObjectID
|
||||
func (fs *WebFileSystem) Write(filePath string, file *FileHeader, data interface{}) (primitive.ObjectID, primitive.ObjectID, error) {
|
||||
headerId, dataId, err := fs.writeFileToMongo(file, data)
|
||||
// Deprecated
|
||||
func (fs *WebFileSystem) findFileInMongo(filter primitive.D) (*WebFSFile, error) {
|
||||
res := fs.webfsCollection.FindOne(context.Background(), &filter)
|
||||
file := WebFSFile{}
|
||||
err := res.Decode(&file)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
return nil, err
|
||||
}
|
||||
parentPath := fs.GetParentPath(filePath)
|
||||
parentDir, err := fs.FindFile(parentPath)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
}
|
||||
|
||||
if parentDir.IsZero() {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, errors.New("parent dir not found")
|
||||
}
|
||||
err = fs.AppendChildToDirectory(headerId, parentDir)
|
||||
if err != nil {
|
||||
return primitive.NilObjectID, primitive.NilObjectID, err
|
||||
}
|
||||
return headerId, dataId, nil
|
||||
return &file, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) UpdateFileData(file *FileHeader, data interface{}) error {
|
||||
update := bson.M{"$set": data}
|
||||
// println("updating data file: " + file.MongoId.String())
|
||||
res, err := fs.webfsFilesData.UpdateByID(fs.ctx, file.Data, update)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if res.ModifiedCount < 1 {
|
||||
return errors.New("no data updated")
|
||||
}
|
||||
return err
|
||||
func (fs *WebFileSystem) castInsertId(res *mongo.InsertOneResult) primitive.ObjectID {
|
||||
return res.InsertedID.(primitive.ObjectID)
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) InitFS() error { //FIXME Can't set parent_id to itself
|
||||
rootData := DirectoryData{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Parent: primitive.NewObjectID(),
|
||||
Children: []primitive.ObjectID{},
|
||||
}
|
||||
rootHeader := FileHeader{
|
||||
MongoId: primitive.NewObjectID(),
|
||||
Name: "/",
|
||||
Type: "directory",
|
||||
Icon: "",
|
||||
}
|
||||
_, _, err := fs.writeFileToMongo(&rootHeader, &rootData)
|
||||
func (fs *WebFileSystem) insertFileToDirectory(fileId primitive.ObjectID, directoryId primitive.ObjectID) error {
|
||||
dir, err := fs.ReadByObjectID(directoryId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//TODO get on boot and safe to struct
|
||||
func (fs *WebFileSystem) GetRootDir() (*FileHeader, *DirectoryData, error) {
|
||||
filter := primitive.M{
|
||||
"name": "/",
|
||||
}
|
||||
res := fs.webfsFilesTable.FindOne(fs.ctx, filter)
|
||||
if res == nil {
|
||||
return nil, nil, errors.New("TODO") //TODO
|
||||
}
|
||||
rootDir := FileHeader{}
|
||||
err := res.Decode(&rootDir)
|
||||
if res == nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
filterData := primitive.M{
|
||||
"_id": rootDir.Data,
|
||||
}
|
||||
resData := fs.webfsFilesData.FindOne(fs.ctx, filterData)
|
||||
if resData.Err() != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
rootDirData := DirectoryData{}
|
||||
err = resData.Decode(&rootDirData)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return &rootDir, &rootDirData, nil
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) Remove(filePath string) error {
|
||||
parentPath := fs.GetParentPath(filePath)
|
||||
parentDirId, err := fs.FindFile(parentPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//TODO: Check, if parent file is dir
|
||||
parentDirData := DirectoryData{}
|
||||
parentDir, err := fs.readFSDocs(parentDirId, &parentDirData)
|
||||
//TODO check if file exist
|
||||
fileData := DirectoryData{}
|
||||
err = mapstructure.Decode(dir.Data.(primitive.D).Map(), &fileData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fileData.Children = append(fileData.Children, fileId)
|
||||
|
||||
fileId, err := fs.FindFile(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newChildren := []primitive.ObjectID{}
|
||||
for _, childId := range parentDirData.Children {
|
||||
if childId != fileId {
|
||||
newChildren = append(newChildren, childId)
|
||||
}
|
||||
}
|
||||
|
||||
parentDirData.Children = newChildren
|
||||
err = fs.UpdateFileData(parentDir, parentDirData)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fs.webfsCollection.UpdateByID(context.Background(), directoryId, bson.M{"$set": bson.M{"data": fileData}})
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -184,8 +86,96 @@ func (fs *WebFileSystem) GetExtension(filename string) string {
|
||||
|
||||
func (fs *WebFileSystem) GetParentPath(path string) string {
|
||||
splittedPath := fs.SplitPath(path)
|
||||
if len(splittedPath) > 1 {
|
||||
return "/" + strings.Join(splittedPath[1:len(splittedPath)-1], "/")
|
||||
}
|
||||
return "/"
|
||||
parentPath := strings.Join(splittedPath[:len(splittedPath)-1], "/")
|
||||
return parentPath
|
||||
}
|
||||
|
||||
func (fs *WebFileSystem) Delete(filePath string) error {
|
||||
// splittedPath := fs.SplitPath(filePath)
|
||||
// parentPath := fs.GetParentPath(filePath)
|
||||
|
||||
_, err := fs.NewRead(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = fs.removeMongo(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = fs.Validate() //FIXME
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//Delete from parent folder
|
||||
// parentDir, err := fs.NewRead(parentPath)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// parentDirData, err := castToDirectoryData(parentDir.Data)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
// newChildrenSlice := []primitive.ObjectID{}
|
||||
// for i := 0; i < len(parentDirData.Children); i++ {
|
||||
// if parentDirData.Children[i] != file.MongoId {
|
||||
// newChildrenSlice = append(newChildrenSlice, parentDirData.Children[i])
|
||||
// }
|
||||
// }
|
||||
|
||||
// parentDirData.Children = newChildrenSlice
|
||||
// parentDir.Data = parentDirData
|
||||
// parentParentDir := fs.GetParentPath(parentPath)
|
||||
|
||||
// _, err = fs.writeMongo(*parentDir, parentParentDir)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
|
||||
return nil
|
||||
|
||||
// for _, childId := range parentDirData.Children {
|
||||
// // read := readStruct{
|
||||
// // File: filePath,
|
||||
// // Filter: primitive.M{
|
||||
// // "_id": childId,
|
||||
// // },
|
||||
// // }
|
||||
// // childFile, err := fs.ReadByObjectID(childId)
|
||||
// // if err != nil {
|
||||
// // println(err.Error())
|
||||
// // continue
|
||||
// // }
|
||||
// // println(childFile.Name + " " + chil)
|
||||
// if file.MongoId == childId {
|
||||
// println(file.Name)
|
||||
// parentDirData.Children.
|
||||
// }
|
||||
// }
|
||||
|
||||
// update:= primitive.M{
|
||||
// "data.children":
|
||||
// }
|
||||
// filter := primitive.M{}
|
||||
// res, err := fs.webfsCollection.UpdateByID(context.Background(), parentDir.MongoId, primitive.M{"$unset": bson.M{"data.children." + file.MongoId.String(): ""}})
|
||||
// res, err := fs.webfsCollection.UpdateOne(context.Background(), filter, primitive.M{"$unset": bson.M{"data.children." + file.MongoId.String(): ""}})
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// if res.MatchedCount < 1 {
|
||||
// return errors.New("no documents found")
|
||||
// }
|
||||
// return nil
|
||||
}
|
||||
|
||||
type WebFSFile struct {
|
||||
MongoId primitive.ObjectID `bson:"_id" json:"-"`
|
||||
Name string `bson:"name" json:"name"`
|
||||
Type string `bson:"type" json:"type"`
|
||||
Icon string `bson:"-" json:"icon"`
|
||||
Data interface{} `bson:"data" json:"-"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user