Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

chore: add service version

boojack74ab42069f58
diff --git a/VERSION b/VERSION
new file mode 100644
index 000000000..8a9ecc2ea
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.0.1
\ No newline at end of file
diff --git a/api/memo.go b/api/memo.go
index 7c373cc41..001f7e6c7 100644
--- a/api/memo.go
+++ b/api/memo.go
@@ -16,7 +16,7 @@ type Memo struct {
type MemoCreate struct {
// Standard fields
CreatorID int
- // Used to import memos with clearly created ts.
+ // Used to import memos with a clearly created ts.
CreatedTs *int64 `json:"createdTs"`
// Domain specific fields
@@ -27,7 +27,6 @@ type MemoPatch struct {
ID int
// Standard fields
- CreatedTs *int64 `json:"createdTs"`
RowStatus *string `json:"rowStatus"`
// Domain specific fields
@@ -43,5 +42,5 @@ type MemoFind struct {
}
type MemoDelete struct {
- ID *int `json:"id"`
+ ID int `json:"id"`
}
diff --git a/api/system.go b/api/system.go
index 5f7c96fed..71aa7806c 100644
--- a/api/system.go
+++ b/api/system.go
@@ -1,5 +1,8 @@
package api
+import "memos/common"
+
type SystemStatus struct {
- Owner *User `json:"owner"`
+ Owner *User `json:"owner"`
+ Profile *common.Profile `json:"profile"`
}
diff --git a/bin/server/cmd/root.go b/bin/server/cmd/root.go
index fa25f14c4..a8572e463 100644
--- a/bin/server/cmd/root.go
+++ b/bin/server/cmd/root.go
@@ -11,10 +11,6 @@ import (
type Main struct {
profile *common.Profile
-
- server *server.Server
-
- db *store.DB
}
func (m *Main) Run() error {
@@ -23,15 +19,11 @@ func (m *Main) Run() error {
return fmt.Errorf("cannot open db: %w", err)
}
- m.db = db
-
s := server.NewServer(m.profile)
storeInstance := store.New(db)
s.Store = storeInstance
- m.server = s
-
if err := s.Run(); err != nil {
return err
}
@@ -42,7 +34,7 @@ func (m *Main) Run() error {
func Execute() {
profile := common.GetProfile()
m := Main{
- profile: &profile,
+ profile: profile,
}
err := m.Run()
diff --git a/common/profile.go b/common/profile.go
index f171308a7..36f010a08 100644
--- a/common/profile.go
+++ b/common/profile.go
@@ -11,10 +11,12 @@ import (
type Profile struct {
// Mode can be "prod" or "dev"
Mode string `json:"mode"`
- // Port is the binding port for server.
+ // Port is the binding port for server
Port int `json:"port"`
// DSN points to where Memos stores its own data
DSN string `json:"dsn"`
+ // Version is the current version of server
+ Version string `json:"version"`
}
func checkDSN(dataDir string) (string, error) {
@@ -38,8 +40,22 @@ func checkDSN(dataDir string) (string, error) {
return dataDir, nil
}
+func getSystemVersion() string {
+ absPath, err := filepath.Abs("./VERSION")
+ if err != nil {
+ return "0.0.0"
+ }
+
+ data, err := os.ReadFile(absPath)
+ if err != nil {
+ return "0.0.0"
+ }
+
+ return string(data)
+}
+
// GetDevProfile will return a profile for dev.
-func GetProfile() Profile {
+func GetProfile() *Profile {
mode := os.Getenv("mode")
if mode != "dev" && mode != "prod" {
mode = "dev"
@@ -63,9 +79,12 @@ func GetProfile() Profile {
dsn := fmt.Sprintf("%s/memos_%s.db", dataDir, mode)
- return Profile{
- Mode: mode,
- Port: port,
- DSN: dsn,
+ version := getSystemVersion()
+
+ return &Profile{
+ Mode: mode,
+ Port: port,
+ DSN: dsn,
+ Version: version,
}
}
diff --git a/server/memo.go b/server/memo.go
index aac31c576..b8f6a9ebf 100644
--- a/server/memo.go
+++ b/server/memo.go
@@ -116,7 +116,7 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
}
memoDelete := &api.MemoDelete{
- ID: &memoID,
+ ID: memoID,
}
err = s.Store.DeleteMemo(memoDelete)
diff --git a/server/system.go b/server/system.go
index 70a933875..58058cbe8 100644
--- a/server/system.go
+++ b/server/system.go
@@ -29,7 +29,8 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
}
systemStatus := api.SystemStatus{
- Owner: ownerUser,
+ Owner: ownerUser,
+ Profile: s.Profile,
}
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)
diff --git a/store/memo.go b/store/memo.go
index bcd9c7928..545b33833 100644
--- a/store/memo.go
+++ b/store/memo.go
@@ -107,9 +107,6 @@ func patchMemo(db *DB, patch *api.MemoPatch) (*api.Memo, error) {
if v := patch.RowStatus; v != nil {
set, args = append(set, "row_status = ?"), append(args, *v)
}
- if v := patch.CreatedTs; v != nil {
- set, args = append(set, "created_ts = ?"), append(args, *v)
- }
args = append(args, patch.ID)
diff --git a/store/migration/10001__schema.sql b/store/migration/10001__schema.sql
index 501086ed7..e7f9ddd74 100644
--- a/store/migration/10001__schema.sql
+++ b/store/migration/10001__schema.sql
@@ -1,13 +1,13 @@
-- user
CREATE TABLE user (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
email TEXT NOT NULL UNIQUE,
role TEXT NOT NULL CHECK (role IN ('OWNER', 'USER')) DEFAULT 'USER',
name TEXT NOT NULL,
password_hash TEXT NOT NULL,
- open_id TEXT NOT NULL UNIQUE,
- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now'))
+ open_id TEXT NOT NULL UNIQUE
);
INSERT INTO
@@ -30,12 +30,12 @@ END;
-- memo
CREATE TABLE memo (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ creator_id INTEGER NOT NULL,
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
-- allowed row status are 'NORMAL', 'ARCHIVED', 'HIDDEN'.
row_status TEXT NOT NULL DEFAULT 'NORMAL',
content TEXT NOT NULL DEFAULT '',
- creator_id INTEGER NOT NULL,
FOREIGN KEY(creator_id) REFERENCES users(id)
);
@@ -59,12 +59,11 @@ END;
-- shortcut
CREATE TABLE shortcut (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ creator_id INTEGER NOT NULL,
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
-
title TEXT NOT NULL DEFAULT '',
payload TEXT NOT NULL DEFAULT '{}',
- creator_id INTEGER NOT NULL,
-- allowed row status are 'NORMAL', 'ARCHIVED'.
row_status TEXT NOT NULL DEFAULT 'NORMAL',
FOREIGN KEY(creator_id) REFERENCES users(id)
@@ -90,13 +89,13 @@ END;
-- resource
CREATE TABLE resource (
id INTEGER PRIMARY KEY AUTOINCREMENT,
+ creator_id INTEGER NOT NULL,
+ created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
+ updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
filename TEXT NOT NULL DEFAULT '',
blob BLOB NOT NULL,
type TEXT NOT NULL DEFAULT '',
size INTEGER NOT NULL DEFAULT 0,
- created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
- creator_id INTEGER NOT NULL,
FOREIGN KEY(creator_id) REFERENCES users(id)
);
diff --git a/web/src/components/AboutSiteDialog.tsx b/web/src/components/AboutSiteDialog.tsx
index aa20f1caa..047f0f38f 100644
--- a/web/src/components/AboutSiteDialog.tsx
+++ b/web/src/components/AboutSiteDialog.tsx
@@ -1,21 +1,24 @@
import { useEffect, useState } from "react";
-import utils from "../helpers/utils";
+import api from "../helpers/api";
+import Only from "./common/OnlyWhen";
import { showDialog } from "./Dialog";
import "../less/about-site-dialog.less";
interface Props extends DialogProps {}
const AboutSiteDialog: React.FC<Props> = ({ destroy }: Props) => {
- const [lastUpdatedAt, setLastUpdatedAt] = useState("");
+ const [profile, setProfile] = useState<Profile>();
useEffect(() => {
try {
- fetch("https://api.github.com/repos/justmemos/memos/commits/main").then(async (res) => {
- const data = (await res.json()) as any;
- setLastUpdatedAt(utils.getDateTimeString(new Date(data.commit.committer.date)));
+ api.getSystemStatus().then(({ profile }) => {
+ setProfile(profile);
});
} catch (error) {
- setLastUpdatedAt("2017/12/31");
+ setProfile({
+ mode: "dev",
+ version: "0.0.0",
+ });
}
}, []);
@@ -35,16 +38,17 @@ const AboutSiteDialog: React.FC<Props> = ({ destroy }: Props) => {
</div>
<div className="dialog-content-container">
<p>
- Memos is an open source, quickly self-hosted alternative <a href="https://flomoapp.com">flomo</a>.
+ Memos is an open source, quickly self-hosted alternative to <a href="https://flomoapp.com">flomo</a>.
</p>
<br />
<p>
- πŸ— <a href="https://github.com/justmemos/memos">This project</a> is working in progress, and very pleasure to your{" "}
- <a href="https://github.com/justmemos/memos/issues">PRs</a>.
- </p>
- <p className="updated-time-text">
- Last updated on <span className="pre-text">{lastUpdatedAt}</span> πŸŽ‰
+ <a href="https://github.com/justmemos/memos">πŸ— Source code</a>, and built by <a href="https://github.com/boojack">Steven 🐯</a>.
</p>
+ <Only when={profile !== undefined}>
+ <p className="updated-time-text">
+ version: <span className="pre-text">{profile?.version}</span> πŸŽ‰
+ </p>
+ </Only>
</div>
</>
);
diff --git a/web/src/less/about-site-dialog.less b/web/src/less/about-site-dialog.less
index 4c09eacb8..6f65faddb 100644
--- a/web/src/less/about-site-dialog.less
+++ b/web/src/less/about-site-dialog.less
@@ -2,7 +2,7 @@
.about-site-dialog {
> .dialog-container {
- @apply w-128;
+ @apply w-96;
> .dialog-content-container {
@apply leading-relaxed;
@@ -20,15 +20,6 @@
@apply font-mono;
}
- > .btn {
- @apply px-2 py-1 text-white rounded text-sm;
- background-color: @text-green;
-
- &:hover {
- @apply opacity-80;
- }
- }
-
a {
@apply cursor-pointer underline-offset-2 underline text-blue-600;
}
diff --git a/web/src/types/api.d.ts b/web/src/types/api.d.ts
index 1b765692b..7dff44513 100644
--- a/web/src/types/api.d.ts
+++ b/web/src/types/api.d.ts
@@ -1,6 +1,7 @@
declare namespace API {
interface SystemStatus {
owner: Model.User;
+ profile: Profile;
}
interface UserCreate {
diff --git a/web/src/types/module/system.d.ts b/web/src/types/module/system.d.ts
new file mode 100644
index 000000000..b039a4d5b
--- /dev/null
+++ b/web/src/types/module/system.d.ts
@@ -0,0 +1,4 @@
+interface Profile {
+ mode: string;
+ version: string;
+}