Skip to content

Commit

Permalink
feat(parser): add lastUpdatedAt field (#644)
Browse files Browse the repository at this point in the history
Co-authored-by: Elsie <[email protected]>
  • Loading branch information
saenai255 and Elsie19 authored Dec 7, 2023
1 parent f6991e1 commit 5a8e601
Show file tree
Hide file tree
Showing 59 changed files with 803 additions and 842 deletions.
10 changes: 10 additions & 0 deletions client/src/components/package-details/PackageDetailsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const Entry: FC<{
</>
)

const UNKNOWN_DATE_SENTINEL = '0001-01-01T00:00:00Z'

const PackageDetailsTable: FC<{
data: PackageInfo
dependencyCount: number
Expand Down Expand Up @@ -62,6 +64,14 @@ const PackageDetailsTable: FC<{
<PackageDetailsMaintainer text={data.maintainer} />
</Entry>

<Entry header={t('packageDetails.table.lastUpdatedAt')}>
{data.lastUpdatedAt === UNKNOWN_DATE_SENTINEL
? '-'
: new Intl.DateTimeFormat().format(
new Date(data.lastUpdatedAt),
)}
</Entry>

<Entry header={t('packageDetails.table.dependencies')}>
{dependencyCount
? displayNumber(dependencyCount)
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/en-US.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default <Locale>{
maintainer: 'Maintainer',
dependencies: 'Dependencies',
requiredBy: 'Required By',
lastUpdatedAt: 'Last Updated At',
},
orphaned: 'Orphaned',
noResults: 'None',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/es-ES.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export default <Locale>{
maintainer: 'Mantenedor',
dependencies: 'Dependencias',
requiredBy: 'Requierdo por',
lastUpdatedAt: 'Última actualización',
},
orphaned: 'Huérfanos',
noResults: 'Nada',
Expand All @@ -120,6 +121,7 @@ export default <Locale>{
runtimeDependencies: 'Dependencias del tiempo de Ejecución',
pacstallDependencies: 'Dependencias de Pacstall',
name: 'Nombre',
version: 'Versión',
close: 'Cerrar',
provider: 'Proveedor',
noDescription: 'No hay descripción disponible',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/fr-FR.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default <Locale>{
maintainer: 'Mainteneur',
dependencies: 'Dépendances',
requiredBy: 'Requis par',
lastUpdatedAt: 'Dernière mise à jour',
},
orphaned: 'Orphelin',
noResults: 'Aucun',
Expand All @@ -122,6 +123,7 @@ export default <Locale>{
close: 'Fermer',
provider: 'Fournisseur',
noDescription: 'Aucune description disponible',
version: 'Version',
},
requiredByModal: {
title: 'Requis par',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/id-ID.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default <Locale>{
maintainer: 'Pemelihara',
dependencies: 'Dependensi',
requiredBy: 'Dibutuhkan oleh',
lastUpdatedAt: 'Diperbarui pada',
},
orphaned: 'Ditelantarkan',
noResults: 'Tidak ditemukan',
Expand All @@ -121,6 +122,7 @@ export default <Locale>{
close: 'Tutup',
provider: 'Penyedia',
noDescription: 'Deskripsi tidak tersedia',
version: 'Versi',
},
requiredByModal: {
title: 'Disediakan oleh',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/it-IT.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default <Locale>{
maintainer: 'Mantenitore',
dependencies: 'Dipendenze',
requiredBy: 'Richiesto da',
lastUpdatedAt: 'Ultimo aggiornamento',
},
orphaned: 'Orfano',
noResults: 'Nessuno',
Expand All @@ -121,6 +122,7 @@ export default <Locale>{
close: 'Chiudi',
provider: 'Fornitore',
noDescription: 'Nessuna descrizione disponibile',
version: 'Versione',
},
requiredByModal: {
title: 'Richiesto da',
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ export default interface Locale {
maintainer: string
dependencies: string
requiredBy: string
lastUpdatedAt: string
}
noResults: string
orphaned: string
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/nl-NL.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default <Locale>{
maintainer: 'Onderhouder',
dependencies: 'Afhankelijkheden',
requiredBy: 'Vereist Door',
lastUpdatedAt: 'Laatst Bijgewerkt Op',
},
orphaned: 'Verweesd',
noResults: 'Geen',
Expand All @@ -121,6 +122,7 @@ export default <Locale>{
close: 'Sluiten',
provider: 'Aanbieder',
noDescription: 'Geen omschrijving beschikbaar',
version: 'Versie',
},
requiredByModal: {
title: 'Vereist Door',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/pl-PL.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export default <Locale>{
maintainer: 'Twórca',
dependencies: 'Zależności',
requiredBy: 'Wymagany przez',
lastUpdatedAt: 'Ostatnio zaktualizowany',
},
orphaned: 'Nie utrzymywany',
noResults: 'Brak',
Expand All @@ -122,6 +123,7 @@ export default <Locale>{
close: 'Zamknij',
provider: 'Dostawca',
noDescription: 'Brak opisu',
version: 'Wersja',
},
requiredByModal: {
title: 'Wymagany przez',
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/pt-BR.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default <Locale>{
maintainer: 'Mantenedor',
dependencies: 'Dependências',
requiredBy: 'Requerido Por',
lastUpdatedAt: 'Última Atualização',
},
orphaned: 'Órfão',
noResults: 'Nenhum',
Expand Down
1 change: 1 addition & 0 deletions client/src/locale/pt-PT.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default <Locale>{
maintainer: 'Responsável',
dependencies: 'Dependências',
requiredBy: 'Requerido Por',
lastUpdatedAt: 'Última Atualização',
},
orphaned: 'Órfão',
noResults: 'Nenhum',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/ro-RO.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default <Locale>{
maintainer: 'Menținut de',
dependencies: 'Dependențe',
requiredBy: 'Necesar pentru',
lastUpdatedAt: 'Ultima actualizare',
},
orphaned: 'Nemenținut',
noResults: 'Fără',
Expand All @@ -121,6 +122,7 @@ export default <Locale>{
close: 'Închide',
provider: 'Furnizor',
noDescription: 'Nu există o descriere disponibilă',
version: 'Versiune',
},
requiredByModal: {
title: 'Necesar pentru',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/sv-SE.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default <Locale>{
maintainer: 'Underhållare',
dependencies: 'Beroenden',
requiredBy: 'Krävs av',
lastUpdatedAt: 'Senast uppdaterad',
},
orphaned: 'Oandvänd',
noResults: 'Inga resultat',
Expand All @@ -121,6 +122,7 @@ export default <Locale>{
close: 'Stäng',
provider: 'Leverantör',
noDescription: 'Ingen beskrivning finns',
version: 'Version',
},
requiredByModal: {
title: 'Krävs av',
Expand Down
2 changes: 2 additions & 0 deletions client/src/locale/tr-TR.locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export default <Locale>{
maintainer: 'Bakıcı',
dependencies: 'Gereksinimler',
requiredBy: 'Taradından gerekli',
lastUpdatedAt: 'Son güncelleme',
},
orphaned: 'Terk edilmiş',
noResults: 'Hiçbirşey',
Expand All @@ -121,6 +122,7 @@ export default <Locale>{
close: 'Kapat',
provider: 'Sağlayıcı',
noDescription: 'Açıklama mevcut değil',
version: 'Sürüm',
},
requiredByModal: {
title: 'Tarafından Gerekli',
Expand Down
1 change: 1 addition & 0 deletions client/src/types/package-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default interface PackageInfo {
latestVersion?: string
prettyName: string
updateStatus: UpdateStatus
lastUpdatedAt: string
}

export enum UpdateStatus {
Expand Down
11 changes: 11 additions & 0 deletions server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ LDFLAGS= \
all: dist/webserver

test:
PACSTALL_DATABASE_HOST=localhost \
PACSTALL_DATABASE_PORT=3306 \
PACSTALL_DATABASE_USER=root \
PACSTALL_DATABASE_PASSWORD=changeme \
PACSTALL_DATABASE_NAME=pacstall \
PACSTALL_DISCORD_ENABLED=false \
PACSTALL_DISCORD_TOKEN="" \
PACSTALL_DISCORD_CHANNEL_ID="" \
PACSTALL_DISCORD_TAGS="" \
PACSTALL_MATOMO_ENABLED="false" \
PACSTALL_REPOLOGY_ENABLED="false" \
GO_ENV=test go test -v ./...

run:
Expand Down
16 changes: 8 additions & 8 deletions server/bin/webserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,24 @@ func main() {
printLogo()

setupRequests()
log.Info("Registered http requests")
log.Info("registered http requests")

log.Info("Attempting to start TCP listener")
log.Info("attempting to start TCP listener")

server.OnServerOnline(func() {
log.NotifyCustom("🚀 Startup 🧑‍🚀", "Successfully started up.")
log.Info("Server is now online on port %v.\n", config.Port)
log.NotifyCustom("🚀 Startup 🧑‍🚀", "successfully started up.")
log.Info("server is now online on port %v.\n", config.Port)

log.Info("Booted in %v\n", color.GreenString("%v", time.Since(startedAt)))
log.Info("booted in %v\n", color.GreenString("%v", time.Since(startedAt)))

parser.ScheduleRefresh(config.UpdateInterval)
log.Info("Scheduled pacscripts to auto-refresh every %v", config.UpdateInterval)
log.Info("scheduled pacscripts to auto-refresh every %v", config.UpdateInterval)

if config.Repology.Enabled {
repology.ScheduleRefresh(config.RepologyUpdateInterval)
log.Info("Scheduled repology to auto-refresh every %v", config.RepologyUpdateInterval)
log.Info("scheduled repology to auto-refresh every %v", config.RepologyUpdateInterval)
} else {
log.Warn("Repology is disabled. Pacstall will not be able to fetch package data from Repology.")
log.Warn("repository repology is disabled")
}
})

Expand Down
3 changes: 3 additions & 0 deletions server/consts/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package consts

const PACSCRIPT_FILE_EXTENSION = "pacscript"
1 change: 1 addition & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/joomcode/errorx v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/net v0.7.0 // indirect
Expand Down
5 changes: 5 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/bwmarrin/discordgo v0.27.1 h1:ib9AIc/dom1E/fSIulrBwnez0CToJE113ZGt4Ho
github.com/bwmarrin/discordgo v0.27.1/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
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/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
Expand All @@ -23,6 +25,8 @@ github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/joomcode/errorx v1.1.1 h1:/LFG/qSk1gUTuZjs+qlyOJEpcVjD9DXgBNFhdZkQrjY=
github.com/joomcode/errorx v1.1.1/go.mod h1:eQzdtdlNyN7etw6YCS4W4+lu442waxZYw5yvz0ULrRo=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
Expand All @@ -33,6 +37,7 @@ github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D
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.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/treelightsoftware/go-matomo v0.1.0-beta h1:lTSvp3XCwEjS8allzntKLj6Hyd1HgYHn4SrbtMp0+s0=
Expand Down
14 changes: 7 additions & 7 deletions server/repology/fetch.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package repology

import (
"errors"
"fmt"
"strings"

"github.com/joomcode/errorx"
"pacstall.dev/webserver/model"
"pacstall.dev/webserver/types/list"
"pacstall.dev/webserver/types/array"
)

func parseRepologyFilter(filter string) (string, string) {
Expand All @@ -30,7 +30,7 @@ func findRepologyProject(search []string) (model.RepologyProjectProvider, error)
var result model.RepologyProjectProvider

if len(search) == 0 {
return result, fmt.Errorf("no search terms provided")
return result, errorx.IllegalArgument.New("no search terms provided")
}

db := model.Instance()
Expand All @@ -41,15 +41,15 @@ func findRepologyProject(search []string) (model.RepologyProjectProvider, error)
filterName, filterValue := parseRepologyFilter(filter)
column, ok := repologyFilterToColumn[filterName]
if !ok {
return result, fmt.Errorf("invalid filter '%v'", filterName)
return result, errorx.IllegalArgument.New("invalid filter '%v'", filterName)
}

query = query.Where(fmt.Sprintf("%v = ?", column), filterValue)
}

var results []model.RepologyProjectProvider
if err := query.Order("version desc").Find(&results).Error; err != nil || len(results) == 0 {
return result, errors.Join(errors.New("failed to fetch repology project"), err)
return result, errorx.Decorate(err, "failed to fetch repology project")
}

results = sortByStatus(results)
Expand All @@ -72,7 +72,7 @@ var repologyStatusPriority = map[string]int{
}

func sortByStatus(projects []model.RepologyProjectProvider) []model.RepologyProjectProvider {
return list.From(projects).SortBy(func(p1, p2 model.RepologyProjectProvider) bool {
return array.SortBy(array.Clone(projects), func(p1, p2 model.RepologyProjectProvider) bool {
return repologyStatusPriority[p1.Status] < repologyStatusPriority[p2.Status]
}).ToSlice()
})
}
2 changes: 1 addition & 1 deletion server/repology/internal/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func ExportRepologyDatabase(db *gorm.DB) error {
delay := makeSecondDelay()
defer delay.Wait()

log.Debug("Page %v | Cursor at: %v", it, lastProjectName)
log.Debug("page %v | cursor at: %v", it, lastProjectName)
projectPage, err := getProjectSearch(lastProjectName)
if err != nil {
return errors.Join(errors.New("failed to fetch repology project page"), err)
Expand Down
6 changes: 3 additions & 3 deletions server/repology/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ func ScheduleRefresh(every time.Duration) {
go func() {
for {
db := model.Instance()
log.Info("Refreshing Repology database...")
log.Info("refreshing Repology database...")
err := ExportRepologyDatabase(db)
if err != nil {
log.Error("Failed to export Repology projects: %v", err)
log.Error("failed to export Repology projects: %v", err)
} else {
log.Info("Repology database refreshed successfully")
log.Info("repology database refreshed successfully")
}

time.Sleep(every)
Expand Down
Loading

0 comments on commit 5a8e601

Please sign in to comment.