Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F12217627
nodeinfo.go
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
nodeinfo.go
View Options
package
writefreely
import
(
"github.com/writeas/go-nodeinfo"
"github.com/writeas/web-core/log"
"github.com/writeas/writefreely/config"
"strings"
)
type
nodeInfoResolver
struct
{
cfg
*
config
.
Config
db
*
datastore
}
func
nodeInfoConfig
(
db
*
datastore
,
cfg
*
config
.
Config
)
*
nodeinfo
.
Config
{
name
:=
cfg
.
App
.
SiteName
desc
:=
"Minimal, federated blogging platform."
if
cfg
.
App
.
SingleUser
{
// Fetch blog information, instead
coll
,
err
:=
db
.
GetCollectionByID
(
1
)
if
err
==
nil
{
desc
=
coll
.
Description
}
}
return
&
nodeinfo
.
Config
{
BaseURL
:
cfg
.
App
.
Host
,
InfoURL
:
"/api/nodeinfo"
,
Metadata
:
nodeinfo
.
Metadata
{
NodeName
:
name
,
NodeDescription
:
desc
,
Private
:
cfg
.
App
.
Private
,
Software
:
nodeinfo
.
SoftwareMeta
{
HomePage
:
softwareURL
,
GitHub
:
"https://github.com/writeas/writefreely"
,
Follow
:
"https://writing.exchange/@write_as"
,
},
},
Protocols
:
[]
nodeinfo
.
NodeProtocol
{
nodeinfo
.
ProtocolActivityPub
,
},
Services
:
nodeinfo
.
Services
{
Inbound
:
[]
nodeinfo
.
NodeService
{},
Outbound
:
[]
nodeinfo
.
NodeService
{
nodeinfo
.
ServiceRSS
,
},
},
Software
:
nodeinfo
.
SoftwareInfo
{
Name
:
strings
.
ToLower
(
serverSoftware
),
Version
:
softwareVer
,
},
}
}
func
(
r
nodeInfoResolver
)
IsOpenRegistration
()
(
bool
,
error
)
{
return
r
.
cfg
.
App
.
OpenRegistration
,
nil
}
func
(
r
nodeInfoResolver
)
Usage
()
(
nodeinfo
.
Usage
,
error
)
{
var
collCount
,
postCount
,
activeHalfYear
,
activeMonth
int
err
:=
r
.
db
.
QueryRow
(
`SELECT COUNT(*) FROM collections`
).
Scan
(
&
collCount
)
if
err
!=
nil
{
collCount
=
0
}
err
=
r
.
db
.
QueryRow
(
`SELECT COUNT(*) FROM posts`
).
Scan
(
&
postCount
)
if
err
!=
nil
{
log
.
Error
(
"Unable to fetch post counts: %v"
,
err
)
}
if
r
.
cfg
.
App
.
PublicStats
{
// Display bi-yearly / monthly stats
err
=
r
.
db
.
QueryRow
(
`SELECT COUNT(*) FROM (
SELECT DISTINCT collection_id
FROM posts
INNER JOIN collections c
ON collection_id = c.id
WHERE collection_id IS NOT NULL
AND updated > DATE_SUB(NOW(), INTERVAL 6 MONTH)) co`
).
Scan
(
&
activeHalfYear
)
err
=
r
.
db
.
QueryRow
(
`SELECT COUNT(*) FROM (
SELECT DISTINCT collection_id
FROM posts
INNER JOIN FROM collections c
ON collection_id = c.id
WHERE collection_id IS NOT NULL
AND updated > DATE_SUB(NOW(), INTERVAL 1 MONTH)) co`
).
Scan
(
&
activeMonth
)
}
return
nodeinfo
.
Usage
{
Users
:
nodeinfo
.
UsageUsers
{
Total
:
collCount
,
ActiveHalfYear
:
activeHalfYear
,
ActiveMonth
:
activeMonth
,
},
LocalPosts
:
postCount
,
},
nil
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Oct 30, 3:27 AM (2 h, 25 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3460141
Attached To
rWF WriteFreely
Event Timeline
Log In to Comment