Compare commits

..

3 Commits

Author SHA1 Message Date
f81e15f1b8 Add cat lib with route 2023-05-10 01:19:06 +03:00
da8af8222d move from comments init css zoom and finder desktop 2023-05-10 01:18:54 +03:00
61cbf717c3 Add todo 2023-05-10 01:18:02 +03:00
6 changed files with 76 additions and 9 deletions

57
libs/cat.go Normal file
View File

@ -0,0 +1,57 @@
package libs
import (
"errors"
"net/http"
"personalwebsite/webfilesystem"
"github.com/gin-gonic/gin"
)
type Cat struct {
fs *webfilesystem.WebFileSystem
}
func NewCatLib(webfs *webfilesystem.WebFileSystem) *Cat {
return &Cat{
fs: webfs,
}
}
func (c *Cat) Get(filePath string) (string, error) {
file, err := c.fs.Read(filePath, nil)
if err != nil {
return "", err
}
if file.Type != "plaintext" {
return "", errors.New("todo")
}
fileData := webfilesystem.PlainTextFileData{}
_, err = c.fs.Read(filePath, &fileData)
if err != nil {
return "", err
}
return fileData.Data, nil
}
func (c *Cat) 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
return
}
data, err := c.Get(path)
if err != nil {
ctx.Status(http.StatusInternalServerError)
return
}
ctx.String(http.StatusOK, "plaintext", data)
})
}

View File

@ -5,11 +5,13 @@ import (
)
type Libs struct {
imglib *ImagLib
Imglib *ImagLib
Cat *Cat
}
func NewLibs(webfs *webfilesystem.WebFileSystem) Libs {
return Libs{
imglib: NewImgLib(webfs),
Imglib: NewImgLib(webfs),
Cat: NewCatLib(webfs),
}
}

View File

@ -89,6 +89,12 @@ func main() {
imgLib.Route(imgLibGroup)
}
catLibGroup := libsGroup.Group("cat")
{
catLib := libs.NewCatLib(webfs)
catLib.Route(catLibGroup)
}
appsStorageGroup := libsGroup.Group("apps")
{
appsStorage.Route(appsStorageGroup)

View File

@ -20,14 +20,11 @@ class WebDesktopEnvironment{
static Applications = {};
static isMobile = false
constructor(){
// WebDesktopEnvironment.Open("finder", ["/home/user", "desktop", document.querySelector('#desktop-layer')])
//TODO create key -desktop-mode
// WebDesktopEnvironment.isMobile = WebDesktopEnvironment.CheckMobile()
document.body.style.setProperty('--zoom', 1)
this.wc = new WindowsCompositor()
this.loadWDE()
return
// WebDesktopEnvironment.isMobile = WebDesktopEnvironment.CheckMobile()
// let applications = document.createElement("div")
// applications.setAttribute('id', 'applications')
@ -66,7 +63,6 @@ class WebDesktopEnvironment{
})
} else{
document.body.style.setProperty('--zoom', 1)
// let desktopLayer = document.createElement("div")
// desktopLayer.setAttribute('id', 'desktop-layer')

View File

@ -11,6 +11,7 @@
</div>
<div id="ContentBorder" class="ContentBorder AdjectiveElement">
<div class="FinderContent">
<!-- TODO Fix ConvexElement -->
<div class="ToolBar ConvexElement">
<button id="RootButton">/</button>
<button id="HomeButton">Home</button>

View File

@ -44,6 +44,11 @@ type BinaryFileData struct {
Bin []byte `bson:"bin" json:"-"`
}
type PlainTextFileData struct {
MongoId primitive.ObjectID `bson:"_id" json:"-"`
Data string `bson:"data" json:"data"`
}
// Deprecated
func (fs *WebFileSystem) ReadHeader(fileID primitive.ObjectID) (*FileHeader, error) {
file := &FileHeader{}