aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-06-23 03:11:14 +0900
committernsfisis <nsfisis@gmail.com>2025-06-23 03:15:54 +0900
commite95b823f6554f5bad24be1c7f04b2adc763a9f92 (patch)
tree3cb3e220143cf51e4e60b26283a905393aa6ba94 /backend
parent27bfc8f1d9588322d85197e31b7346601cc680b3 (diff)
downloadfeedaka-e95b823f6554f5bad24be1c7f04b2adc763a9f92.tar.gz
feedaka-e95b823f6554f5bad24be1c7f04b2adc763a9f92.tar.zst
feedaka-e95b823f6554f5bad24be1c7f04b2adc763a9f92.zip
refactor: change directory structure
Diffstat (limited to 'backend')
-rw-r--r--backend/go.mod33
-rw-r--r--backend/go.sum124
-rw-r--r--backend/main.go509
-rw-r--r--backend/static/favicon.svg7
-rw-r--r--backend/static/index.js47
-rw-r--r--backend/templates/read-feeds.html35
-rw-r--r--backend/templates/settings.html22
-rw-r--r--backend/templates/unread-feeds.html35
8 files changed, 812 insertions, 0 deletions
diff --git a/backend/go.mod b/backend/go.mod
new file mode 100644
index 0000000..0e7289c
--- /dev/null
+++ b/backend/go.mod
@@ -0,0 +1,33 @@
+module undef.ninja/x/feedaka
+
+go 1.23.0
+
+toolchain go1.24.4
+
+require (
+ github.com/hashicorp/go-multierror v1.1.1
+ github.com/labstack/echo/v4 v4.13.4
+ github.com/mattn/go-sqlite3 v1.14.28
+ github.com/mmcdole/gofeed v1.3.0
+ golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b
+)
+
+require (
+ github.com/PuerkitoBio/goquery v1.10.3 // indirect
+ github.com/andybalholm/cascadia v1.3.3 // indirect
+ github.com/hashicorp/errwrap v1.1.0 // indirect
+ github.com/json-iterator/go v1.1.12 // indirect
+ github.com/labstack/gommon v0.4.2 // indirect
+ github.com/mattn/go-colorable v0.1.14 // indirect
+ github.com/mattn/go-isatty v0.0.20 // indirect
+ github.com/mmcdole/goxpp v1.1.1 // indirect
+ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
+ github.com/modern-go/reflect2 v1.0.2 // indirect
+ github.com/valyala/bytebufferpool v1.0.0 // indirect
+ github.com/valyala/fasttemplate v1.2.2 // indirect
+ golang.org/x/crypto v0.39.0 // indirect
+ golang.org/x/net v0.41.0 // indirect
+ golang.org/x/sys v0.33.0 // indirect
+ golang.org/x/text v0.26.0 // indirect
+ golang.org/x/time v0.12.0 // indirect
+)
diff --git a/backend/go.sum b/backend/go.sum
new file mode 100644
index 0000000..8c95773
--- /dev/null
+++ b/backend/go.sum
@@ -0,0 +1,124 @@
+github.com/PuerkitoBio/goquery v1.10.3 h1:pFYcNSqHxBD06Fpj/KsbStFRsgRATgnf3LeXiUkhzPo=
+github.com/PuerkitoBio/goquery v1.10.3/go.mod h1:tMUX0zDMHXYlAQk6p35XxQMqMweEKB7iK7iLNd4RH4Y=
+github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM=
+github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
+github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
+github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
+github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
+github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
+github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
+github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
+github.com/labstack/echo/v4 v4.13.4 h1:oTZZW+T3s9gAu5L8vmzihV7/lkXGZuITzTQkTEhcXEA=
+github.com/labstack/echo/v4 v4.13.4/go.mod h1:g63b33BZ5vZzcIUF8AtRH40DrTlXnx4UMC8rBdndmjQ=
+github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0=
+github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
+github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
+github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
+github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
+github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
+github.com/mattn/go-sqlite3 v1.14.28 h1:ThEiQrnbtumT+QMknw63Befp/ce/nUPgBPMlRFEum7A=
+github.com/mattn/go-sqlite3 v1.14.28/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
+github.com/mmcdole/gofeed v1.3.0 h1:5yn+HeqlcvjMeAI4gu6T+crm7d0anY85+M+v6fIFNG4=
+github.com/mmcdole/gofeed v1.3.0/go.mod h1:9TGv2LcJhdXePDzxiuMnukhV2/zb6VtnZt1mS+SjkLE=
+github.com/mmcdole/goxpp v1.1.1 h1:RGIX+D6iQRIunGHrKqnA2+700XMCnNv0bAOOv5MUhx8=
+github.com/mmcdole/goxpp v1.1.1/go.mod h1:v+25+lT2ViuQ7mVxcncQ8ch1URund48oH+jhjiwEgS8=
+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
+github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
+github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
+github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
+github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
+github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
+github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
+github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
+github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
+golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
+golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
+golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
+golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
+golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
+golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
+golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
+golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
+golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
+golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
+golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
+golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
+golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
+golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
+golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
+golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
+golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
+golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
+golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
+golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
+golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
+golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
+golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
+golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
+golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
+golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
+golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
+golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
+golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
+golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
+golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
+golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
+golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
+golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
+golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
+golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M=
+golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA=
+golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
+golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
+golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
+golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
+golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
diff --git a/backend/main.go b/backend/main.go
new file mode 100644
index 0000000..018a4b2
--- /dev/null
+++ b/backend/main.go
@@ -0,0 +1,509 @@
+package main
+
+import (
+ "context"
+ "database/sql"
+ "embed"
+ "fmt"
+ "html/template"
+ "io"
+ "log"
+ "net/http"
+ "os"
+ "strconv"
+ "strings"
+ "time"
+
+ "github.com/hashicorp/go-multierror"
+ "github.com/labstack/echo/v4"
+ "github.com/labstack/echo/v4/middleware"
+ _ "github.com/mattn/go-sqlite3"
+ "github.com/mmcdole/gofeed"
+ "golang.org/x/exp/slices"
+)
+
+var (
+ basePath string
+ db *sql.DB
+ //go:embed templates/*
+ tmplFS embed.FS
+ //go:embed static/*
+ staticFS embed.FS
+)
+
+type Template struct {
+ templates *template.Template
+}
+
+func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
+ return t.templates.ExecuteTemplate(w, name, data)
+}
+
+func initDB(db *sql.DB) error {
+ _, err := db.Exec(`
+CREATE TABLE IF NOT EXISTS feeds (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ url TEXT NOT NULL,
+ title TEXT NOT NULL,
+ fetched_at TEXT NOT NULL
+);
+
+CREATE TABLE IF NOT EXISTS articles (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+ feed_id INTEGER NOT NULL,
+ guid TEXT NOT NULL,
+ title TEXT NOT NULL,
+ url TEXT NOT NULL,
+ is_read INTEGER NOT NULL
+);
+`)
+ return err
+}
+
+func getIndex(c echo.Context) error {
+ // Redirect to /feeds/unread
+ return c.Redirect(http.StatusFound, basePath+"/feeds/unread")
+}
+
+func getSettings(c echo.Context) error {
+ feedURLs := []string{}
+ rows, err := db.Query(`SELECT url FROM feeds`)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var url string
+ err := rows.Scan(&url)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ feedURLs = append(feedURLs, url)
+ }
+ // Sort feedURLs in ascending order.
+ slices.Sort(feedURLs)
+
+ return c.Render(http.StatusOK, "settings.html", struct {
+ BasePath string
+ URLs string
+ }{
+ BasePath: basePath,
+ URLs: strings.Join(feedURLs, "\r\n"),
+ })
+}
+
+func postSettings(c echo.Context) error {
+ // Get "urls" from form parameters.
+ rawUrls := strings.Split(c.FormValue("urls"), "\r\n")
+ urls := make([]string, 0, len(rawUrls))
+ for _, rawUrl := range rawUrls {
+ url := strings.TrimSpace(rawUrl)
+ if url != "" {
+ urls = append(urls, url)
+ }
+ }
+ existingURLs := make(map[string]bool)
+ rows, err := db.Query(`SELECT url FROM feeds`)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ defer rows.Close()
+ for rows.Next() {
+ var url string
+ err := rows.Scan(&url)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ existingURLs[url] = true
+ }
+ for _, url := range urls {
+ if existingURLs[url] {
+ continue
+ }
+ _, err := db.Exec(
+ `INSERT INTO feeds (url, title, fetched_at) VALUES (?, ?, ?)`,
+ url,
+ "",
+ time.Now().AddDate(0, 0, -1).UTC().Format(time.RFC3339),
+ )
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ }
+ // Remove:
+ for existingURL := range existingURLs {
+ // If existingURL is not in urls, it will be removed.
+ found := false
+ for _, url := range urls {
+ if existingURL == url {
+ found = true
+ break
+ }
+ }
+ if found {
+ continue
+ }
+ // Remove feed and articles.
+ _, err = db.Exec(`DELETE FROM articles WHERE feed_id = (SELECT id FROM feeds WHERE url = ?)`, existingURL)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ _, err := db.Exec(`DELETE FROM feeds WHERE url = ?`, existingURL)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ }
+ return c.Redirect(http.StatusSeeOther, basePath+"/settings")
+}
+
+func fetchOneFeed(feedID int, url string, ctx context.Context) error {
+ log.Printf("Fetching %s...\n", url)
+ fp := gofeed.NewParser()
+ ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
+ defer cancel()
+ feed, err := fp.ParseURLWithContext(url, ctx)
+ if err != nil {
+ return fmt.Errorf("Failed to fetch %s: %v\n", url, err)
+ }
+ _, err = db.Exec(
+ `UPDATE feeds SET title = ?, fetched_at = ? WHERE id = ?`,
+ feed.Title,
+ time.Now().UTC().Format(time.RFC3339),
+ feedID,
+ )
+ if err != nil {
+ return err
+ }
+ rows, err := db.Query(`SELECT guid FROM articles WHERE feed_id = ?`, feedID)
+ if err != nil {
+ return err
+ }
+ defer rows.Close()
+ existingArticleGUIDs := make(map[string]bool)
+ for rows.Next() {
+ var guid string
+ err := rows.Scan(&guid)
+ if err != nil {
+ return err
+ }
+ existingArticleGUIDs[guid] = true
+ }
+ for _, item := range feed.Items {
+ if existingArticleGUIDs[item.GUID] {
+ _, err := db.Exec(
+ `UPDATE articles SET title = ?, url = ? WHERE feed_id = ? AND guid = ?`,
+ item.Title,
+ item.Link,
+ feedID,
+ item.GUID,
+ )
+ if err != nil {
+ return err
+ }
+ } else {
+ _, err := db.Exec(
+ `INSERT INTO articles (feed_id, guid, title, url, is_read) VALUES (?, ?, ?, ?, ?)`,
+ feedID,
+ item.GUID,
+ item.Title,
+ item.Link,
+ 0,
+ )
+ if err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
+func listFeedsToBeFetched() (map[int]string, error) {
+ rows, err := db.Query(`SELECT id, url, fetched_at FROM feeds`)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ feeds := make(map[int]string)
+ for rows.Next() {
+ var feedID int
+ var url string
+ var fetchedAt string
+ err := rows.Scan(&feedID, &url, &fetchedAt)
+ if err != nil {
+ log.Fatal(err)
+ }
+ fetchedAtTime, err := time.Parse(time.RFC3339, fetchedAt)
+ if err != nil {
+ log.Fatal(err)
+ }
+ now := time.Now().UTC()
+ if now.Sub(fetchedAtTime).Minutes() <= 10 {
+ continue
+ }
+ feeds[feedID] = url
+ }
+ return feeds, nil
+}
+
+func fetchAllFeeds(ctx context.Context) error {
+ feeds, err := listFeedsToBeFetched()
+ if err != nil {
+ return err
+ }
+
+ var result *multierror.Error
+ for feedID, url := range feeds {
+ err := fetchOneFeed(feedID, url, ctx)
+ if err != nil {
+ result = multierror.Append(result, err)
+ }
+ time.Sleep(5 * time.Second)
+ }
+ return result.ErrorOrNil()
+}
+
+func getUnreadFeeds(c echo.Context) error {
+ rows, err := db.Query(`
+SELECT a.id, a.title, f.url, f.title, f.id
+FROM articles AS a
+INNER JOIN feeds AS f ON a.feed_id = f.id
+WHERE is_read = 0
+ORDER BY a.id DESC
+LIMIT 100
+`)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ defer rows.Close()
+
+ return renderFeeds(c, "Unread feeds", "unread-feeds.html", rows)
+}
+
+func getReadFeeds(c echo.Context) error {
+ rows, err := db.Query(`
+SELECT a.id, a.title, f.url, f.title, f.id
+FROM articles AS a
+INNER JOIN feeds AS f ON a.feed_id = f.id
+WHERE is_read = 1
+ORDER BY a.id DESC
+LIMIT 100
+`)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ defer rows.Close()
+
+ return renderFeeds(c, "Read feeds", "read-feeds.html", rows)
+}
+
+func renderFeeds(c echo.Context, title string, templateName string, rows *sql.Rows) error {
+ type Article struct {
+ ID int
+ Title string
+ URL string
+ }
+ type Feed struct {
+ ID int
+ URL string
+ Title string
+ Articles []Article
+ }
+ feeds := make(map[int]*Feed)
+ for rows.Next() {
+ var articleID int
+ var articleTitle string
+ var feedURL string
+ var feedTitle string
+ var feedID int
+ err := rows.Scan(&articleID, &articleTitle, &feedURL, &feedTitle, &feedID)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ if _, ok := feeds[feedID]; !ok {
+ feeds[feedID] = &Feed{
+ ID: feedID,
+ URL: feedURL,
+ Title: feedTitle,
+ }
+ }
+ feed := feeds[feedID]
+ feed.Articles = append(feed.Articles, Article{
+ ID: articleID,
+ Title: articleTitle,
+ URL: fmt.Sprintf("%s/articles/%d", basePath, articleID),
+ })
+ }
+
+ sortedFeeds := make([]*Feed, 0, len(feeds))
+ for _, feed := range feeds {
+ sortedFeeds = append(sortedFeeds, feed)
+ }
+ slices.SortFunc(sortedFeeds, func(a, b *Feed) int {
+ // Ascending order by URL.
+ if a.URL < b.URL {
+ return -1
+ } else if a.URL > b.URL {
+ return 1
+ } else {
+ return 0
+ }
+ })
+
+ return c.Render(http.StatusOK, templateName, struct {
+ BasePath string
+ Title string
+ Feeds []*Feed
+ }{
+ BasePath: basePath,
+ Title: title,
+ Feeds: sortedFeeds,
+ })
+}
+
+func getArticle(c echo.Context) error {
+ rawArticleID := c.Param("articleID")
+ articleID, err := strconv.Atoi(rawArticleID)
+ if err != nil {
+ return c.String(http.StatusNotFound, err.Error())
+ }
+ row := db.QueryRow(`SELECT url FROM articles WHERE id = ?`, articleID)
+ if row == nil {
+ return c.String(http.StatusNotFound, "Not found")
+ }
+ var url string
+ err = row.Scan(&url)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ // Turn is_read on.
+ _, err = db.Exec(`UPDATE articles SET is_read = 1 WHERE id = ?`, articleID)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ // Redirect to the article URL.
+ return c.Redirect(http.StatusFound, url)
+}
+
+func apiPutFeedRead(c echo.Context) error {
+ return apiPutFeed(c, "read")
+}
+
+func apiPutFeedUnread(c echo.Context) error {
+ return apiPutFeed(c, "unread")
+}
+
+func apiPutFeed(c echo.Context, op string) error {
+ rawFeedID := c.Param("feedID")
+ feedID, err := strconv.Atoi(rawFeedID)
+ if err != nil {
+ return c.String(http.StatusNotFound, err.Error())
+ }
+ // Turn is_read on or off.
+ var isReadValue int
+ if op == "read" {
+ isReadValue = 1
+ } else if op == "unread" {
+ isReadValue = 0
+ }
+ _, err = db.Exec(`UPDATE articles SET is_read = ? WHERE feed_id = ?`, isReadValue, feedID)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ return c.NoContent(http.StatusOK)
+}
+
+func apiPutArticleRead(c echo.Context) error {
+ return apiPutArticle(c, "read")
+}
+
+func apiPutArticleUnread(c echo.Context) error {
+ return apiPutArticle(c, "unread")
+}
+
+func apiPutArticle(c echo.Context, op string) error {
+ rawArticleID := c.Param("articleID")
+ articleID, err := strconv.Atoi(rawArticleID)
+ if err != nil {
+ return c.String(http.StatusNotFound, err.Error())
+ }
+ // Turn is_read on or off.
+ var isReadValue int
+ if op == "read" {
+ isReadValue = 1
+ } else if op == "unread" {
+ isReadValue = 0
+ }
+ _, err = db.Exec(`UPDATE articles SET is_read = ? WHERE id = ?`, isReadValue, articleID)
+ if err != nil {
+ return c.String(http.StatusInternalServerError, err.Error())
+ }
+ return c.NoContent(http.StatusOK)
+}
+
+func scheduled(ctx context.Context, d time.Duration, fn func()) {
+ ticker := time.NewTicker(d)
+ go func() {
+ for {
+ select {
+ case <-ticker.C:
+ fn()
+ case <-ctx.Done():
+ return
+ }
+ }
+ }()
+}
+
+func main() {
+ basePath = os.Getenv("FEEDAKA_BASE_PATH")
+ port := os.Getenv("FEEDAKA_PORT")
+
+ var err error
+ db, err = sql.Open("sqlite3", "feedaka.db")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer db.Close()
+
+ err = initDB(db)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ t := &Template{
+ templates: template.Must(template.ParseFS(tmplFS, "templates/*.html")),
+ }
+
+ e := echo.New()
+
+ e.Renderer = t
+ e.Use(middleware.Logger())
+ e.Use(middleware.Recover())
+
+ e.GET("/", getIndex)
+ e.GET("/settings", getSettings)
+ e.POST("/settings", postSettings)
+ e.GET("/feeds/unread", getUnreadFeeds)
+ e.GET("/feeds/read", getReadFeeds)
+ e.GET("/articles/:articleID", getArticle)
+
+ e.PUT("/api/feeds/:feedID/read", apiPutFeedRead)
+ e.PUT("/api/feeds/:feedID/unread", apiPutFeedUnread)
+ e.PUT("/api/articles/:articleID/read", apiPutArticleRead)
+ e.PUT("/api/articles/:articleID/unread", apiPutArticleUnread)
+
+ e.GET("/static/*", echo.WrapHandler(http.FileServer(http.FS(staticFS))))
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ scheduled(ctx, 1*time.Hour, func() {
+ err := fetchAllFeeds(ctx)
+ if err != nil {
+ log.Printf("Failed to fetch feeds: %v\n", err)
+ }
+ })
+
+ err = http.ListenAndServe(":"+port, http.StripPrefix(basePath, e))
+ log.Println(err)
+}
diff --git a/backend/static/favicon.svg b/backend/static/favicon.svg
new file mode 100644
index 0000000..3602b2c
--- /dev/null
+++ b/backend/static/favicon.svg
@@ -0,0 +1,7 @@
+<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">
+ <rect x="0" y="0" width="100" height="100" rx="8" ry="8" fill="skyblue" />
+ <path d="M 0,18 L 74,18 A 8,8 0 0 1 82,26 L 82,100 L 0,100 L 0,18" fill="white" />
+ <path d="M 0,36 L 56,36 A 8,8 0 0 1 64,44 L 64,100 L 0,100 L 0,36" fill="skyblue" />
+ <path d="M 0,54 L 38,54 A 8,8 0 0 1 46,62 L 46,100 L 0,100 L 0,54" fill="white" />
+ <rect x="0" y="72" width="28" height="28" rx="8" ry="8" fill="skyblue" />
+</svg>
diff --git a/backend/static/index.js b/backend/static/index.js
new file mode 100644
index 0000000..6354bbd
--- /dev/null
+++ b/backend/static/index.js
@@ -0,0 +1,47 @@
+const markAllArticles = (feedId, el, read) => {
+ const basePath = window.BASE_PATH;
+ const apiUrl = `${basePath}/api/feeds/${feedId}/${read ? "read" : "unread"}`;
+ fetch(apiUrl, { method: "PUT" })
+ .then((_data) => {
+ el.parentNode.nextElementSibling.remove();
+ el.parentNode.remove();
+ })
+ .catch((error) => {
+ alert(error);
+ });
+};
+
+const markOneArticle = (articleId, el, read) => {
+ const basePath = window.BASE_PATH;
+ const apiUrl = `${basePath}/api/articles/${articleId}/${read ? "read" : "unread"}`;
+ fetch(apiUrl, { method: "PUT" })
+ .then((_data) => {
+ el.parentNode.remove();
+ })
+ .catch((error) => {
+ alert(error);
+ });
+};
+
+document.addEventListener("DOMContentLoaded", () => {
+ document.querySelectorAll(".js-unread-feed").forEach((el) => {
+ el.addEventListener("click", () => {
+ markAllArticles(el.dataset.feedId, el, false);
+ });
+ });
+ document.querySelectorAll(".js-unread-article").forEach((el) => {
+ el.addEventListener("click", () => {
+ markOneArticle(el.dataset.articleId, el, false);
+ });
+ });
+ document.querySelectorAll(".js-read-feed").forEach((el) => {
+ el.addEventListener("click", () => {
+ markAllArticles(el.dataset.feedId, el, true);
+ });
+ });
+ document.querySelectorAll(".js-read-article").forEach((el) => {
+ el.addEventListener("click", () => {
+ markOneArticle(el.dataset.articleId, el, true);
+ });
+ });
+});
diff --git a/backend/templates/read-feeds.html b/backend/templates/read-feeds.html
new file mode 100644
index 0000000..08a2626
--- /dev/null
+++ b/backend/templates/read-feeds.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="{{.BasePath}}/static/style.css">
+ <link rel="icon" href="{{.BasePath}}/static/favicon.svg">
+ <title>{{.Title}} | feedaka</title>
+ </head>
+ <body class="bg-gray-100 text-gray-900 font-sans antialiased">
+ <div class="mx-auto mt-10 px-6">
+ <h1 class="text-4xl font-bold underline mb-8">{{.Title}}</h1>
+ <main>
+ <ul class="list-none pl-5">
+ {{- range .Feeds -}}
+ <li class="mb-5">
+ <a href="{{.URL}}" target="_blank" rel="noreferrer" class="text-blue-500 hover:text-blue-600 hover:underline">{{.Title}}</a>
+ <button data-feed-id="{{.ID}}" class="js-unread-feed ml-4 py-1 px-0 w-6 h-6 rounded border-2 border-green-500 bg-green-500 hover:bg-transparent focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50 transition duration-200"></button>
+ </li>
+ <ul class="list-none pl-5 mt-4">
+ {{- range .Articles -}}
+ <li class="mb-3">
+ <a href="{{.URL}}" target="_blank" rel="noreferrer" class="text-blue-500 hover:text-blue-600 hover:underline">{{.Title}}</a>
+ <button data-article-id="{{.ID}}" class="js-unread-article ml-4 py-1 px-0 w-6 h-6 rounded border-2 border-green-500 bg-green-500 hover:bg-transparent focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50 transition duration-200"></button>
+ </li>
+ {{- end -}}
+ </ul>
+ {{- end -}}
+ </ul>
+ </main>
+ </div>
+ <script>window.BASE_PATH = "{{.BasePath}}";</script>
+ <script src="{{.BasePath}}/static/index.js" type="module" defer></script>
+ </body>
+</html>
diff --git a/backend/templates/settings.html b/backend/templates/settings.html
new file mode 100644
index 0000000..65efd8d
--- /dev/null
+++ b/backend/templates/settings.html
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="{{.BasePath}}/static/style.css">
+ <link rel="icon" href="{{.BasePath}}/static/favicon.svg">
+ <title>Settings | feedaka</title>
+ </head>
+ <body class="bg-gray-100 text-gray-900 font-sans antialiased">
+ <div class="mx-auto mt-10 px-6">
+ <h1 class="text-4xl font-bold underline mb-8">Settings</h1>
+ <main>
+ <h2 class="text-2xl mb-3">URLs</h2>
+ <form method="POST" class="space-y-4">
+ <textarea name="urls" rows="10" cols="80" class="w-full p-2 border rounded resize-y">{{.URLs}}</textarea>
+ <input type="submit" value="Submit" class="py-2 px-4 bg-blue-600 text-white rounded hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-opacity-50" />
+ </form>
+ </main>
+ </div>
+ </body>
+</html>
diff --git a/backend/templates/unread-feeds.html b/backend/templates/unread-feeds.html
new file mode 100644
index 0000000..676f24e
--- /dev/null
+++ b/backend/templates/unread-feeds.html
@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <link rel="stylesheet" href="{{.BasePath}}/static/style.css">
+ <link rel="icon" href="{{.BasePath}}/static/favicon.svg">
+ <title>{{.Title}} | feedaka</title>
+ </head>
+ <body class="bg-gray-100 text-gray-900 font-sans antialiased">
+ <div class="mx-auto mt-10 px-6">
+ <h1 class="text-4xl font-bold underline mb-8">{{.Title}}</h1>
+ <main>
+ <ul class="list-none pl-5">
+ {{- range .Feeds -}}
+ <li class="mb-5">
+ <a href="{{.URL}}" target="_blank" rel="noreferrer" class="text-blue-500 hover:text-blue-600 hover:underline">{{.Title}}</a>
+ <button data-feed-id="{{.ID}}" class="js-read-feed ml-4 py-1 px-0 w-6 h-6 rounded border-2 border-green-500 hover:bg-green-500 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50 transition duration-200"></button>
+ </li>
+ <ul class="list-none pl-5 mt-4">
+ {{- range .Articles -}}
+ <li class="mb-3">
+ <a href="{{.URL}}" target="_blank" rel="noreferrer" class="text-blue-500 hover:text-blue-600 hover:underline">{{.Title}}</a>
+ <button data-article-id="{{.ID}}" class="js-read-article ml-4 py-1 px-0 w-6 h-6 rounded border-2 border-green-500 hover:bg-green-500 focus:outline-none focus:ring-2 focus:ring-green-500 focus:ring-opacity-50 transition duration-200"></button>
+ </li>
+ {{- end -}}
+ </ul>
+ {{- end -}}
+ </ul>
+ </main>
+ </div>
+ <script>window.BASE_PATH = "{{.BasePath}}";</script>
+ <script src="{{.BasePath}}/static/index.js" type="module" defer></script>
+ </body>
+</html>