From 74ab42069f585c7c5f418734cb8f540d1adc36f5 Mon Sep 17 00:00:00 2001 From: boojack Date: Tue, 17 May 2022 21:21:13 +0800 Subject: [PATCH] chore: add service version --- VERSION | 1 + api/memo.go | 5 ++--- api/system.go | 5 ++++- bin/server/cmd/root.go | 10 +-------- common/profile.go | 31 +++++++++++++++++++++----- server/memo.go | 2 +- server/system.go | 3 ++- store/memo.go | 3 --- store/migration/10001__schema.sql | 17 +++++++------- web/src/components/AboutSiteDialog.tsx | 28 +++++++++++++---------- web/src/less/about-site-dialog.less | 11 +-------- web/src/types/api.d.ts | 1 + web/src/types/module/system.d.ts | 4 ++++ 13 files changed, 66 insertions(+), 55 deletions(-) create mode 100644 VERSION create mode 100644 web/src/types/module/system.d.ts diff --git a/VERSION b/VERSION new file mode 100644 index 0000000000000..8a9ecc2ea99d6 --- /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 7c373cc41a025..001f7e6c7848c 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 5f7c96feddb5d..71aa7806c288a 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 fa25f14c4642f..a8572e463e8b5 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 f171308a7fd79..36f010a084d4f 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 aac31c576e918..b8f6a9ebfee06 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 70a933875a625..58058cbe87f64 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 bcd9c7928fc95..545b338339e4e 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 501086ed76b16..e7f9ddd743f62 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 aa20f1caa6523..047f0f38f608b 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 = ({ destroy }: Props) => { - const [lastUpdatedAt, setLastUpdatedAt] = useState(""); + const [profile, setProfile] = useState(); 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 = ({ destroy }: Props) => {

- Memos is an open source, quickly self-hosted alternative flomo. + Memos is an open source, quickly self-hosted alternative to flomo.


- 🏗 This project is working in progress, and very pleasure to your{" "} - PRs. -

-

- Last updated on {lastUpdatedAt} 🎉 + 🏗 Source code, and built by Steven 🐯.

+ +

+ version: {profile?.version} 🎉 +

+
); diff --git a/web/src/less/about-site-dialog.less b/web/src/less/about-site-dialog.less index 4c09eacb846f9..6f65faddb23b1 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 1b765692be105..7dff445132ee3 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 0000000000000..b039a4d5b4d84 --- /dev/null +++ b/web/src/types/module/system.d.ts @@ -0,0 +1,4 @@ +interface Profile { + mode: string; + version: string; +}