Commit Diff


commit - e48f0422427ae70cc25ac8b2c39a671eca141898
commit + ed1a61d7093471344579fb8d0e3632134dc1dc26
blob - 605b1a4b77e149252b6236d64f044a0630fc3255
blob + bd1795926b312ddc9dce198b5d47f1f447fae10c
--- fs/file.go
+++ fs/file.go
@@ -126,6 +126,7 @@ func (f *lFile) ReadDir(n int) ([]fs.DirEntry, error) 
 				c := c
 				f.dirinfo.entries = append(f.dirinfo.entries, fs.FileInfoToDirEntry(&c))
 			}
+			f.dirinfo.entries = append(f.dirinfo.entries, postFile(p))
 		default:
 			return nil, &fs.PathError{"readdir", f.info.Name(), fmt.Errorf("not a directory")}
 		}
@@ -147,6 +148,15 @@ func postText(p *lemmy.Post) *bytes.Buffer {
 	return buf
 }
 
+func postFile(p *lemmy.Post) *dummy {
+	return &dummy{
+		name:     "post",
+		mode:     0o444,
+		mtime:    p.ModTime(),
+		contents: postText(p).Bytes(),
+	}
+}
+
 func commentText(c *lemmy.Comment) *bytes.Buffer {
 	buf := &bytes.Buffer{}
 	fmt.Fprintln(buf, "From:", c.CreatorID)
blob - 77cd53b4dd55e445d66dfc46f9e648ebb44357da
blob + c22a508e7f453da8e6d42bfc052b08f902576ece
--- fs/fs.go
+++ fs/fs.go
@@ -107,6 +107,17 @@ func (fsys *FS) Open(name string) (fs.File, error) {
 			client: fsys.Client,
 		}, nil
 	}
+	if elems[2] == "post" {
+		info, err := postFile(&post).Stat()
+		if err != nil {
+			return nil, &fs.PathError{"open", name, fmt.Errorf("prepare post file info: %w", err)}
+		}
+		return &lFile{
+			info:   info,
+			buf:    io.NopCloser(postText(&post)),
+			client: fsys.Client,
+		}, nil
+	}
 
 	id, err = strconv.Atoi(elems[2])
 	if err != nil {