Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rss-to-listmonk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Uni-Film-Club
rss-to-listmonk
Commits
5d9f1d44
Verified
Commit
5d9f1d44
authored
2 years ago
by
David Mehren
Browse files
Options
Downloads
Patches
Plain Diff
Add more logging, safeguards and don't start campaigns by default
parent
5c576d89
No related branches found
No related tags found
No related merge requests found
Pipeline
#110312
passed
2 years ago
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/config.ts
+6
-2
6 additions, 2 deletions
src/config.ts
src/index.ts
+12
-2
12 additions, 2 deletions
src/index.ts
src/listmonk.ts
+7
-2
7 additions, 2 deletions
src/listmonk.ts
with
25 additions
and
6 deletions
src/config.ts
+
6
−
2
View file @
5d9f1d44
...
@@ -3,10 +3,12 @@ export var config: {
...
@@ -3,10 +3,12 @@ export var config: {
apiPassword
:
string
apiPassword
:
string
feedUrl
:
string
feedUrl
:
string
interval
:
number
interval
:
number
listmonkBaseUrl
:
string
listmonkBaseUrl
:
string
,
sendMails
:
boolean
}
}
export
function
parseConfig
()
{
export
function
parseConfig
()
{
console
.
log
(
"
Parsing config
"
)
config
=
{
config
=
{
apiUser
:
parseEnvironmentVariable
(
'
LISTMONK_API_USER
'
),
apiUser
:
parseEnvironmentVariable
(
'
LISTMONK_API_USER
'
),
apiPassword
:
parseEnvironmentVariable
(
'
LISTMONK_API_PASSWORD
'
),
apiPassword
:
parseEnvironmentVariable
(
'
LISTMONK_API_PASSWORD
'
),
...
@@ -14,12 +16,14 @@ export function parseConfig() {
...
@@ -14,12 +16,14 @@ export function parseConfig() {
interval
:
Number
.
parseInt
(
interval
:
Number
.
parseInt
(
parseEnvironmentVariable
(
'
LISTMONK_CHECK_INTERVAL
'
)
parseEnvironmentVariable
(
'
LISTMONK_CHECK_INTERVAL
'
)
),
),
listmonkBaseUrl
:
parseEnvironmentVariable
(
'
LISTMONK_BASE_URL
'
)
listmonkBaseUrl
:
parseEnvironmentVariable
(
'
LISTMONK_BASE_URL
'
),
sendMails
:
parseEnvironmentVariable
(
'
LISTMONK_SEND_MAILS
'
)
===
'
true
'
,
}
}
if
(
Number
.
isNaN
(
config
.
interval
))
{
if
(
Number
.
isNaN
(
config
.
interval
))
{
console
.
error
(
'
LISTMONK_CHECK_INTERVAL must be a number
'
)
console
.
error
(
'
LISTMONK_CHECK_INTERVAL must be a number
'
)
process
.
exit
(
1
)
process
.
exit
(
1
)
}
}
console
.
log
(
"
Config successfully parsed
"
)
}
}
function
parseEnvironmentVariable
(
variableName
:
string
):
string
{
function
parseEnvironmentVariable
(
variableName
:
string
):
string
{
...
...
This diff is collapsed.
Click to expand it.
src/index.ts
+
12
−
2
View file @
5d9f1d44
...
@@ -9,24 +9,34 @@ import cron from 'node-cron'
...
@@ -9,24 +9,34 @@ import cron from 'node-cron'
import
{
config
,
parseConfig
}
from
'
./config
'
import
{
config
,
parseConfig
}
from
'
./config
'
async
function
processRssItem
(
rssItem
:
FeedItem
,
campaigns
:
CampaignDetails
[])
{
async
function
processRssItem
(
rssItem
:
FeedItem
,
campaigns
:
CampaignDetails
[])
{
console
.
log
(
`Processing RSS item
${
rssItem
.
title
}
(GUID:
${
rssItem
.
guid
}
)`
)
const
campaign
=
campaigns
.
find
(
const
campaign
=
campaigns
.
find
(
(
campaign
)
=>
(
campaign
)
=>
campaign
.
tags
.
find
((
tag
)
=>
tag
===
`id:
${
rssItem
.
guid
}
`
)
!==
undefined
campaign
.
tags
.
find
((
tag
)
=>
tag
===
`id:
${
rssItem
.
guid
}
`
)
!==
undefined
)
)
if
(
campaign
!==
undefined
)
{
if
(
campaign
!==
undefined
)
{
console
.
log
(
`Campaign for GUID
${
rssItem
.
guid
}
already exists`
)
return
return
}
}
console
.
log
(
`
"
${
rssItem
.
title
}
" doesn't exist.
`
)
console
.
log
(
`
Creating campaign for GUID
${
rssItem
.
guid
}
`
)
const
details
=
await
createCampaign
(
const
details
=
await
createCampaign
(
rssItem
.
title
,
rssItem
.
title
,
rssItem
.
guid
,
rssItem
.
guid
,
rssItem
.
content
rssItem
.
content
)
)
if
(
config
.
sendMails
)
{
console
.
log
(
`Starting campaign for GUID
${
rssItem
.
guid
}
`
)
await
startCampaign
(
details
.
id
)
await
startCampaign
(
details
.
id
)
}
}
else
{
console
.
log
(
'
Sending mails is disabled
'
)
}
}
function
main
()
{
function
main
()
{
;(
async
()
=>
{
;(
async
()
=>
{
console
.
log
(
"
Starting main loop
"
)
const
campaigns
=
await
listCampaigns
()
const
campaigns
=
await
listCampaigns
()
const
rssItems
=
await
readRssFeed
()
const
rssItems
=
await
readRssFeed
()
...
...
This diff is collapsed.
Click to expand it.
src/listmonk.ts
+
7
−
2
View file @
5d9f1d44
...
@@ -92,12 +92,17 @@ export interface CampaignListResponse {
...
@@ -92,12 +92,17 @@ export interface CampaignListResponse {
}
}
export
async
function
listCampaigns
():
Promise
<
CampaignListResponse
>
{
export
async
function
listCampaigns
():
Promise
<
CampaignListResponse
>
{
console
.
log
(
'
Fetch campaigns
'
)
console
.
log
(
'
Fetch
ing
campaigns
'
)
const
response
=
await
listmonkRequest
<
CampaignListResponse
>
(
const
response
=
await
listmonkRequest
<
CampaignListResponse
>
(
'
get
'
,
'
get
'
,
'
campaigns?per_page=skip
'
,
'
campaigns?per_page=skip
'
,
undefined
undefined
)
)
console
.
log
(
`Found
${
response
.
total
}
campaigns`
)
console
.
log
(
`Campaign array has length
${
response
.
results
.
length
}
`
)
console
.
log
(
`Response says we should have
${
response
.
total
}
total campaigns`
)
if
(
response
.
results
.
length
!==
response
.
total
)
{
console
.
log
(
'
ERROR: Campaign array has different length than response total
'
)
process
.
exit
(
1
);
}
return
response
return
response
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment