Skip to content

Commit

Permalink
Checkout memos-upstream to v0.18.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthalles committed Dec 15, 2023
2 parents 35c06c1 + 91fecbe commit 9f69d21
Show file tree
Hide file tree
Showing 99 changed files with 2,100 additions and 2,058 deletions.
4 changes: 2 additions & 2 deletions memos-upstream/.github/workflows/frontend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
cache: pnpm
cache-dependency-path: "web/pnpm-lock.yaml"
- run: pnpm install
Expand All @@ -40,7 +40,7 @@ jobs:
version: 8
- uses: actions/setup-node@v4
with:
node-version: "18"
node-version: "20"
cache: pnpm
cache-dependency-path: "web/pnpm-lock.yaml"
- run: pnpm install
Expand Down
2 changes: 1 addition & 1 deletion memos-upstream/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tmp

# Frontend asset
web/dist
server/dist
server/frontend/dist

# build folder
build
Expand Down
6 changes: 6 additions & 0 deletions memos-upstream/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ linters-settings:
disabled: true
- name: early-return
disabled: true
- name: use-any
disabled: true
- name: exported
disabled: true
- name: unhandled-error
disabled: true
gocritic:
disabled-checks:
- ifElseChain
Expand Down
6 changes: 3 additions & 3 deletions memos-upstream/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build frontend dist.
FROM node:18-alpine AS frontend
FROM node:20-alpine AS frontend
WORKDIR /frontend-build

COPY . .
Expand All @@ -15,9 +15,9 @@ FROM golang:1.21-alpine AS backend
WORKDIR /backend-build

COPY . .
COPY --from=frontend /frontend-build/web/dist ./server/dist
COPY --from=frontend /frontend-build/web/dist ./server/frontend/dist

RUN CGO_ENABLED=0 go build -o memos ./main.go
RUN CGO_ENABLED=0 go build -o memos ./bin/memos/main.go

# Make workspace with above generated files.
FROM alpine:latest AS monolithic
Expand Down
24 changes: 15 additions & 9 deletions memos-upstream/api/v1/rss.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package v1

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand All @@ -12,9 +11,11 @@ import (

"github.com/gorilla/feeds"
"github.com/labstack/echo/v4"
"github.com/yuin/goldmark"

"github.com/usememos/memos/internal/util"
"github.com/usememos/memos/plugin/gomark/parser"
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
"github.com/usememos/memos/plugin/gomark/render/html"
"github.com/usememos/memos/store"
)

Expand Down Expand Up @@ -117,10 +118,14 @@ func (s *APIV1Service) generateRSSFromMemoList(ctx context.Context, memoList []*
if err != nil {
return "", err
}
description, err := getRSSItemDescription(memoMessage.Content)
if err != nil {
return "", err
}
feed.Items[i] = &feeds.Item{
Title: getRSSItemTitle(memoMessage.Content),
Link: &feeds.Link{Href: baseURL + "/m/" + fmt.Sprintf("%d", memoMessage.ID)},
Description: getRSSItemDescription(memoMessage.Content),
Description: description,
Created: time.Unix(memoMessage.CreatedTs, 0),
Enclosure: &feeds.Enclosure{Url: baseURL + "/m/" + fmt.Sprintf("%d", memoMessage.ID) + "/image"},
}
Expand Down Expand Up @@ -182,7 +187,7 @@ func getRSSItemTitle(content string) string {
return title
}

func getRSSItemDescription(content string) string {
func getRSSItemDescription(content string) (string, error) {
var description string
if isTitleDefined(content) {
var firstLineEnd = strings.Index(content, "\n")
Expand All @@ -191,12 +196,13 @@ func getRSSItemDescription(content string) string {
description = content
}

// TODO: use our `./plugin/gomark` parser to handle markdown-like content.
var buf bytes.Buffer
if err := goldmark.Convert([]byte(description), &buf); err != nil {
panic(err)
tokens := tokenizer.Tokenize(description)
nodes, err := parser.Parse(tokens)
if err != nil {
return "", err
}
return buf.String()
result := html.NewHTMLRender().Render(nodes)
return result, nil
}

func isTitleDefined(content string) bool {
Expand Down
2 changes: 1 addition & 1 deletion memos-upstream/api/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (s *APIV1Service) GetSystemStatus(c echo.Context) error {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to find system setting list").SetInternal(err)
}
for _, systemSetting := range systemSettingList {
if systemSetting.Name == SystemSettingServerIDName.String() || systemSetting.Name == SystemSettingSecretSessionName.String() || systemSetting.Name == SystemSettingTelegramBotTokenName.String() {
if systemSetting.Name == SystemSettingServerIDName.String() || systemSetting.Name == SystemSettingSecretSessionName.String() || systemSetting.Name == SystemSettingTelegramBotTokenName.String() || systemSetting.Name == SystemSettingInstanceURLName.String() {
continue
}

Expand Down
3 changes: 3 additions & 0 deletions memos-upstream/api/v1/system_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ const (
SystemSettingMemoDisplayWithUpdatedTsName SystemSettingName = "memo-display-with-updated-ts"
// SystemSettingAutoBackupIntervalName is the name of auto backup interval as seconds.
SystemSettingAutoBackupIntervalName SystemSettingName = "auto-backup-interval"
// SystemSettingInstanceURLName is the name of instance url setting.
SystemSettingInstanceURLName SystemSettingName = "instance-url"
)
const systemSettingUnmarshalError = `failed to unmarshal value from system setting "%v"`

Expand Down Expand Up @@ -271,6 +273,7 @@ func (upsert UpsertSystemSettingRequest) Validate() error {
if err := json.Unmarshal([]byte(upsert.Value), &value); err != nil {
return errors.Errorf(systemSettingUnmarshalError, settingName)
}
case SystemSettingInstanceURLName:
default:
return errors.New("invalid system setting name")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd
package main

import (
"context"
Expand Down Expand Up @@ -186,3 +186,10 @@ func printGreetings() {
fmt.Printf("👉GitHub: %s\n", "https://github.com/usememos/memos")
println("---")
}

func main() {
err := Execute()
if err != nil {
panic(err)
}
}
Loading

0 comments on commit 9f69d21

Please sign in to comment.