Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
0aa70853
Unverified
Commit
0aa70853
authored
Apr 17, 2023
by
boojack
Committed by
GitHub
Apr 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: add enclosure to rss (#1559)
parent
994d5dd8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
22 deletions
+33
-22
rss.go
server/rss.go
+33
-22
No files found.
server/rss.go
View file @
0aa70853
...
...
@@ -17,18 +17,15 @@ import (
func
(
s
*
Server
)
registerRSSRoutes
(
g
*
echo
.
Group
)
{
g
.
GET
(
"/explore/rss.xml"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
systemCustomizedProfile
,
err
:=
getSystemCustomizedProfile
(
ctx
,
s
)
systemCustomizedProfile
,
err
:=
s
.
getSystemCustomizedProfile
(
ctx
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to get system customized profile"
)
.
SetInternal
(
err
)
}
normalStatus
:=
api
.
Normal
memoFind
:=
api
.
MemoFind
{
RowStatus
:
&
normalStatus
,
VisibilityList
:
[]
api
.
Visibility
{
api
.
Public
,
},
RowStatus
:
&
normalStatus
,
VisibilityList
:
[]
api
.
Visibility
{
api
.
Public
},
}
memoList
,
err
:=
s
.
Store
.
FindMemoList
(
ctx
,
&
memoFind
)
if
err
!=
nil
{
...
...
@@ -36,35 +33,31 @@ func (s *Server) registerRSSRoutes(g *echo.Group) {
}
baseURL
:=
c
.
Scheme
()
+
"://"
+
c
.
Request
()
.
Host
rss
,
err
:=
generateRSSFromMemoList
(
memoList
,
baseURL
,
systemCustomizedProfile
)
rss
,
err
:=
s
.
generateRSSFromMemoList
(
ctx
,
memoList
,
baseURL
,
systemCustomizedProfile
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to generate rss"
)
.
SetInternal
(
err
)
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationXMLCharsetUTF8
)
return
c
.
String
(
http
.
StatusOK
,
rss
)
})
g
.
GET
(
"/u/:id/rss.xml"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
systemCustomizedProfile
,
err
:=
getSystemCustomizedProfile
(
ctx
,
s
)
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
))
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
Status
InternalServerError
,
"Failed to get system customized profile
"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
Status
BadRequest
,
"User id is not a number
"
)
.
SetInternal
(
err
)
}
id
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"id"
)
)
systemCustomizedProfile
,
err
:=
s
.
getSystemCustomizedProfile
(
ctx
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
Status
BadRequest
,
"User id is not a number
"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
Status
InternalServerError
,
"Failed to get system customized profile
"
)
.
SetInternal
(
err
)
}
normalStatus
:=
api
.
Normal
memoFind
:=
api
.
MemoFind
{
CreatorID
:
&
id
,
RowStatus
:
&
normalStatus
,
VisibilityList
:
[]
api
.
Visibility
{
api
.
Public
,
},
CreatorID
:
&
id
,
RowStatus
:
&
normalStatus
,
VisibilityList
:
[]
api
.
Visibility
{
api
.
Public
},
}
memoList
,
err
:=
s
.
Store
.
FindMemoList
(
ctx
,
&
memoFind
)
if
err
!=
nil
{
...
...
@@ -72,8 +65,7 @@ func (s *Server) registerRSSRoutes(g *echo.Group) {
}
baseURL
:=
c
.
Scheme
()
+
"://"
+
c
.
Request
()
.
Host
rss
,
err
:=
generateRSSFromMemoList
(
memoList
,
baseURL
,
systemCustomizedProfile
)
rss
,
err
:=
s
.
generateRSSFromMemoList
(
ctx
,
memoList
,
baseURL
,
systemCustomizedProfile
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to generate rss"
)
.
SetInternal
(
err
)
}
...
...
@@ -85,7 +77,7 @@ func (s *Server) registerRSSRoutes(g *echo.Group) {
const
MaxRSSItemCount
=
100
const
MaxRSSItemTitleLength
=
100
func
generateRSSFromMemoList
(
memoList
[]
*
api
.
Memo
,
baseURL
string
,
profile
*
api
.
CustomizedProfile
)
(
string
,
error
)
{
func
(
s
*
Server
)
generateRSSFromMemoList
(
ctx
context
.
Context
,
memoList
[]
*
api
.
Memo
,
baseURL
string
,
profile
*
api
.
CustomizedProfile
)
(
string
,
error
)
{
feed
:=
&
feeds
.
Feed
{
Title
:
profile
.
Name
,
Link
:
&
feeds
.
Link
{
Href
:
baseURL
},
...
...
@@ -102,6 +94,25 @@ func generateRSSFromMemoList(memoList []*api.Memo, baseURL string, profile *api.
Link
:
&
feeds
.
Link
{
Href
:
baseURL
+
"/m/"
+
strconv
.
Itoa
(
memo
.
ID
)},
Description
:
getRSSItemDescription
(
memo
.
Content
),
Created
:
time
.
Unix
(
memo
.
CreatedTs
,
0
),
Enclosure
:
&
feeds
.
Enclosure
{
Url
:
baseURL
+
"/m/"
+
strconv
.
Itoa
(
memo
.
ID
)
+
"/image"
},
}
resourceList
,
err
:=
s
.
Store
.
FindResourceList
(
ctx
,
&
api
.
ResourceFind
{
MemoID
:
&
memo
.
ID
,
})
if
err
!=
nil
{
return
""
,
err
}
if
len
(
resourceList
)
>
0
{
enclosure
:=
feeds
.
Enclosure
{}
resource
:=
resourceList
[
0
]
if
resource
.
ExternalLink
!=
""
{
enclosure
.
Url
=
resource
.
ExternalLink
}
else
{
enclosure
.
Url
=
baseURL
+
"/o/r/"
+
strconv
.
Itoa
(
memo
.
ID
)
+
"/"
+
resource
.
PublicID
+
"/"
+
resource
.
Filename
}
enclosure
.
Length
=
strconv
.
Itoa
(
int
(
resource
.
Size
))
enclosure
.
Type
=
resource
.
Type
feed
.
Items
[
i
]
.
Enclosure
=
&
enclosure
}
}
...
...
@@ -112,7 +123,7 @@ func generateRSSFromMemoList(memoList []*api.Memo, baseURL string, profile *api.
return
rss
,
nil
}
func
getSystemCustomizedProfile
(
ctx
context
.
Context
,
s
*
Server
)
(
*
api
.
CustomizedProfile
,
error
)
{
func
(
s
*
Server
)
getSystemCustomizedProfile
(
ctx
context
.
Context
)
(
*
api
.
CustomizedProfile
,
error
)
{
systemSetting
,
err
:=
s
.
Store
.
FindSystemSetting
(
ctx
,
&
api
.
SystemSettingFind
{
Name
:
api
.
SystemSettingCustomizedProfileName
,
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment