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 { type Libs struct {
imglib *ImagLib Imglib *ImagLib
Cat *Cat
} }
func NewLibs(webfs *webfilesystem.WebFileSystem) Libs { func NewLibs(webfs *webfilesystem.WebFileSystem) Libs {
return Libs{ return Libs{
imglib: NewImgLib(webfs), Imglib: NewImgLib(webfs),
Cat: NewCatLib(webfs),
} }
} }

View File

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

View File

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

View File

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

View File

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