mirror of
https://codeberg.org/pluja/kycnot.me
synced 2025-08-16 10:10:52 -04:00
massive update
This commit is contained in:
parent
6decdcb4fb
commit
c64ea21904
46 changed files with 5663 additions and 834 deletions
|
@ -1,10 +1,5 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Attribute struct {
|
||||
ID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
|
@ -13,48 +8,10 @@ type Attribute struct {
|
|||
}
|
||||
|
||||
type AttributeMap struct {
|
||||
Attributes map[string]Attribute `json:"attributes"`
|
||||
}
|
||||
|
||||
func (a *AttributeMap) GetAttribute(key string) Attribute {
|
||||
return a.Attributes[key]
|
||||
}
|
||||
|
||||
func (a *AttributeMap) GetAttributesFromList(attr string) []Attribute {
|
||||
var attributes []Attribute
|
||||
for _, attribute := range strings.Split(attr, ",") {
|
||||
attributes = append(attributes, a.GetAttribute(attribute))
|
||||
}
|
||||
|
||||
// Sort the attributes slice by Rating from worst to best
|
||||
sort.Slice(attributes, func(i, j int) bool {
|
||||
return attributes[i].Rating > attributes[j].Rating
|
||||
})
|
||||
|
||||
return attributes
|
||||
}
|
||||
|
||||
func (a *AttributeMap) GetSortedAttributes(reverse bool) []Attribute {
|
||||
// Return the attributes sorted by Rating from best to worst
|
||||
attributes := make([]Attribute, 0, len(a.Attributes))
|
||||
for _, attr := range a.Attributes {
|
||||
attributes = append(attributes, attr)
|
||||
}
|
||||
sort.Slice(attributes, func(i, j int) bool {
|
||||
if reverse {
|
||||
return attributes[i].Rating > attributes[j].Rating
|
||||
}
|
||||
return attributes[i].Rating < attributes[j].Rating
|
||||
})
|
||||
return attributes
|
||||
Attributes map[string]AttributeNew `json:"attributes"`
|
||||
}
|
||||
|
||||
const (
|
||||
AttributeRatingInfo = 0
|
||||
AttributeRatingGood = 1
|
||||
AttributeRatingWarning = 2
|
||||
AttributeRatingBad = 3
|
||||
|
||||
AttributeAccountNeeded = "account-needed"
|
||||
AttributeAPIAvailable = "api"
|
||||
AttributeBlockFundsIfFlagged = "blocks-if-flagged"
|
||||
|
@ -84,187 +41,161 @@ const (
|
|||
)
|
||||
|
||||
var ServiceAttributes = AttributeMap{
|
||||
Attributes: map[string]Attribute{
|
||||
Attributes: map[string]AttributeNew{
|
||||
AttributeRiskPreventionSystem: {
|
||||
Title: "Automated Risk-Prevention System",
|
||||
Description: "This service scans transactions automatically in search for suspicious transactions. If the trade is flagged suspicious by the system, the user might be required a KYC procedure in order to complete the trade or get a refund.",
|
||||
Rating: AttributeRatingBad,
|
||||
ID: AttributeRiskPreventionSystem,
|
||||
Rating: "bad",
|
||||
},
|
||||
|
||||
AttributeKYCForSomeFeatures: {
|
||||
Title: "KYC is mandatory to use some features",
|
||||
Description: "Some features offered by this service need KYC for the user to use them.",
|
||||
Rating: AttributeRatingBad,
|
||||
ID: AttributeKYCForSomeFeatures,
|
||||
Rating: "bad",
|
||||
},
|
||||
|
||||
AttributeKYCIfObligedByLaw: {
|
||||
Title: "May require KYC/SOF by policy/law",
|
||||
Description: "If obliged to do so by the law or in accordance with the service's internal policy, it may at any time introduce or amend mandatory identification / verification procedures and require the user to complete identification and/or verification and may also require to submit identification documents (KYC) or provide Source of Funds (SOF) information.",
|
||||
Rating: AttributeRatingBad,
|
||||
ID: AttributeKYCIfObligedByLaw,
|
||||
Rating: "bad",
|
||||
},
|
||||
|
||||
AttributeCustodialWallet: {
|
||||
Title: "Custodial wallet",
|
||||
Description: "A custodial wallet is a type of crypto wallet where a third party holds and manages the private keys to your wallet and your assets in custody. The custodian is responsible for safeguarding your funds, and you entrust them with your private keys. Custodial wallets are usually provided by centralized crypto exchanges like Coinbase or Binance. Using a custodial wallet requires a great deal of trust in the institution.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributeCustodialWallet,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributeAccountNeeded: {
|
||||
Title: "Account needed to use the service",
|
||||
Description: "Users require creating and maintaining an account with the service in order to access and use its features. ",
|
||||
Rating: AttributeRatingInfo,
|
||||
ID: AttributeAccountNeeded,
|
||||
Rating: "info",
|
||||
},
|
||||
|
||||
AttributePrivateSourceCode: {
|
||||
Title: "Source code is private",
|
||||
Description: "The source code of the service is not publicly available. This means that the service cannot be audited by the community. This is not necessarily bad, but it is something to keep in mind.",
|
||||
Rating: AttributeRatingInfo,
|
||||
ID: AttributePrivateSourceCode,
|
||||
Rating: "info",
|
||||
},
|
||||
|
||||
AttributeNoCustomerSupport: {
|
||||
Title: "Poor or no customer support",
|
||||
Description: "The service does not offer customer support, or the quality of service provided by the support team is inadequate or unsatisfactory.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributeNoCustomerSupport,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributeBlockFundsIfFlagged: {
|
||||
Title: "May block 'suspicious' transactions",
|
||||
Description: "User funds may pass through an analysis system that may flag the source of the funds as suspicious. If this happens, the user may be refunded or may be required a KYC procedure.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributeBlockFundsIfFlagged,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributeUnclearRefundPolicy: {
|
||||
Title: "Unclear refund policy",
|
||||
Description: "This service has an unclear or nonexistent statement about how they manage user refunds.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributeUnclearRefundPolicy,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributeSellerWalletCustodial: {
|
||||
Title: "The seller wallet is custodial",
|
||||
Description: "The seller wallet is custodial, which means that the seller does not have control over the funds. This is a common practice in P2P exchanges, where the service needs to have control over the funds in order to be able to refund the buyer if the trade enters a dispute.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributeSellerWalletCustodial,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributeRefundRequiresKYC: {
|
||||
Title: "Refunds may require KYC",
|
||||
Description: "In certain cases, the refund process of these services may require the completion of a Know Your Customer (KYC) procedure or the disclosure of personal information. Some services, such as aggregators, usually don't control the KYC procedures of their partners so they fall in this category.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributeRefundRequiresKYC,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributeToSNotScrapable: {
|
||||
Title: "ToS page is not possible to scrape",
|
||||
Description: "The ToS page has some mechanism that makes it impossible for KYCNOT.me to scrape its content. These methods include, for example, using a canvas and rendering the text on it.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributeToSNotScrapable,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributePartnersMayEnforceKYC: {
|
||||
Title: "Partners may enforce KYC policies",
|
||||
Description: "The service has partners that may enforce or implement KYC policies. This is common in aggregators, where the service does not control the KYC policies of their partners.",
|
||||
Rating: AttributeRatingWarning,
|
||||
ID: AttributePartnersMayEnforceKYC,
|
||||
Rating: "warn",
|
||||
},
|
||||
|
||||
AttributeNonCustodialWallet: {
|
||||
Title: "Non-custodial wallet",
|
||||
Description: "A non-custodial wallet is a type of crypto wallet where the user holds and manages the private keys to the wallet and the assets in custody. The user is responsible for safeguarding their funds, and they are the only ones with access to their private keys. Using a non-custodial wallet requires no trust in any institution.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeNonCustodialWallet,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeOpenSource: {
|
||||
Title: "Open source code",
|
||||
Description: "The source code of the service is publicly available. This means that the service can be audited by the community. This is not necessarily good, but it is something to keep in mind.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeOpenSource,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeP2P: {
|
||||
Title: "Peer to peer",
|
||||
Description: "Peer-to-peer marketplaces are online platforms where people can trade goods, cryptocurrencies and services directly from each other, without the need for intermediaries like traditional retailers or service providers. In this case, the service is based on such type of market.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeP2P,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeNoRegistrationNeeded: {
|
||||
Title: "No registration needed",
|
||||
Description: "Users can access and use the service without creating an account. This enables a faster and more convenient user experience while also offering enhanced privacy and anonymity.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeNoRegistrationNeeded,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeNoPersonalInfoNeeded: {
|
||||
Title: "No personal information needed",
|
||||
Description: "Users can create an account with these services without having to provide any personal information such as their name, address, or identification documents. This offers a high degree of privacy and anonymity to users who prefer to keep their personal information private.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeNoPersonalInfoNeeded,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeStrictNoKYCPolicy: {
|
||||
Title: "Strict no-KYC policy",
|
||||
Description: "The service has a strict no-KYC policy, which means that it does not require users to complete any KYC procedure in order to access and use its features.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeStrictNoKYCPolicy,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeRefundNoKYC: {
|
||||
Title: "Refunds do not require KYC",
|
||||
Description: "The refund process of these services does not require the completion of a Know Your Customer (KYC) procedure or the disclosure of personal information.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeRefundNoKYC,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeStrictNoLogPolicy: {
|
||||
Title: "Strict no-log policy",
|
||||
Description: "The service has a strict no-log policy, which means that it does not collect or store any information about its users.",
|
||||
Rating: AttributeRatingGood,
|
||||
ID: AttributeStrictNoLogPolicy,
|
||||
Rating: "good",
|
||||
},
|
||||
|
||||
AttributeMobileAppAvailable: {
|
||||
Title: "Mobile app available",
|
||||
Description: "The service has a mobile app available for download.",
|
||||
Rating: AttributeRatingInfo,
|
||||
ID: AttributeMobileAppAvailable,
|
||||
Rating: "info",
|
||||
},
|
||||
|
||||
AttributeNoJavaScriptNeeded: {
|
||||
Title: "No JavaScript needed",
|
||||
Description: "The service does not require the user to enable JavaScript in order to access and use its features.",
|
||||
Rating: AttributeRatingInfo,
|
||||
ID: AttributeNoJavaScriptNeeded,
|
||||
Rating: "info",
|
||||
},
|
||||
|
||||
AttributeTelegramBotAvailable: {
|
||||
Title: "Telegram bot available",
|
||||
Description: "The service has a Telegram bot available.",
|
||||
Rating: AttributeRatingInfo,
|
||||
ID: AttributeTelegramBotAvailable,
|
||||
Rating: "info",
|
||||
},
|
||||
|
||||
AttributeAPIAvailable: {
|
||||
Title: "API available",
|
||||
Description: "The service has an API available.",
|
||||
Rating: AttributeRatingInfo,
|
||||
ID: AttributeAPIAvailable,
|
||||
Rating: "info",
|
||||
},
|
||||
|
||||
AttributeJavaScriptNeeded: {
|
||||
Title: "JavaScript needed",
|
||||
Description: "The service requires the user to enable JavaScript in order to access and use its features.",
|
||||
Rating: AttributeRatingInfo,
|
||||
ID: AttributeJavaScriptNeeded,
|
||||
Rating: "info",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,184 +0,0 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"pluja.dev/kycnot.me/config"
|
||||
"pluja.dev/kycnot.me/ent"
|
||||
"pluja.dev/kycnot.me/ent/service"
|
||||
)
|
||||
|
||||
var Client *ent.Client
|
||||
|
||||
func AddFakeData() {
|
||||
|
||||
_, err := Client.Service.Create().
|
||||
SetName("bisq").
|
||||
SetLogoURL("https://kycnot.me/static/img/bisq.webp").
|
||||
SetDescription("Buy and sell bitcoin for fiat (or cryptocurrencies) privately and securely using Bisq's peer-to-peer network and open-source desktop software.").
|
||||
SetUrls([]string{"https://bisq.network/"}).
|
||||
SetTosUrls([]string{"https://bisq.wiki/Frequently_asked_questions"}).
|
||||
SetOnionUrls([]string{}).
|
||||
SetKycLevel(0).
|
||||
SetTags("market,p2p,buy,sell,anonymous").
|
||||
SetPending(false).
|
||||
SetListed(true).
|
||||
SetVerified(true).
|
||||
SetXmr(true).
|
||||
SetBtc(true).
|
||||
SetLightning(true).
|
||||
SetFiat(true).
|
||||
SetCash(true).
|
||||
SetScore(10).
|
||||
SetType(service.TypeExchange).
|
||||
SetAttributes(strings.Join([]string{AttributeNonCustodialWallet, AttributeOpenSource, AttributeNoPersonalInfoNeeded, AttributeP2P}, ",")).
|
||||
SetTosHighlights(nil).
|
||||
Save(context.Background())
|
||||
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Could not save service to database")
|
||||
}
|
||||
|
||||
_, _ = Client.Service.Create().
|
||||
SetName("localmonero").
|
||||
SetLogoURL("https://kycnot.me/static/img/localmonero.webp").
|
||||
SetDescription("Peer-to-peer Monero trading platform. A marketplace where users can buy and sell Monero to and from each other. You'll be able to buy and sell online with more than 60 currencies.").
|
||||
SetUrls([]string{"https://localmonero.co/"}).
|
||||
SetTosUrls([]string{"https://localmonero.co/nojs/faq"}).
|
||||
SetOnionUrls([]string{"http://nehdddktmhvqklsnkjqcbpmb63htee2iznpcbs5tgzctipxykpj6yrid.onion/"}).
|
||||
SetKycLevel(1).
|
||||
SetTags("market,p2p,buy,sell").
|
||||
SetPending(false).
|
||||
SetListed(true).
|
||||
SetVerified(true).
|
||||
SetXmr(true).
|
||||
SetBtc(true).
|
||||
SetLightning(false).
|
||||
SetFiat(true).
|
||||
SetCash(true).
|
||||
SetScore(10).
|
||||
SetType(service.TypeExchange).
|
||||
SetAttributes(strings.Join([]string{AttributeNonCustodialWallet, AttributeOpenSource, AttributeNoPersonalInfoNeeded, AttributeP2P}, ",")).
|
||||
SetTosHighlights(nil).
|
||||
Save(context.Background())
|
||||
|
||||
_, _ = Client.Service.Create().
|
||||
SetName("mullvad").
|
||||
SetLogoURL("https://kycnot.me/static/img/mullvad.webp").
|
||||
SetDescription("VPN service. Strict no-logs, open-source clients.").
|
||||
SetUrls([]string{"https://mullvad.net/"}).
|
||||
SetTosUrls([]string{"https://mullvad.net/en/help/terms-service/"}).
|
||||
SetOnionUrls([]string{"http://o54hon2e2vj6c7m3aqqu6uyece65by3vgoxxhlqlsvkmacw6a7m7kiad.onion/en/"}).
|
||||
SetKycLevel(0).
|
||||
SetTags("vpn,private,secure,safe").
|
||||
SetPending(false).
|
||||
SetListed(true).
|
||||
SetVerified(true).
|
||||
SetXmr(true).
|
||||
SetBtc(true).
|
||||
SetLightning(false).
|
||||
SetFiat(true).
|
||||
SetCash(true).
|
||||
SetType(service.TypeService).
|
||||
SetCategory("VPN").
|
||||
SetScore(10).
|
||||
SetAttributes(strings.Join([]string{AttributeStrictNoKYCPolicy, AttributeStrictNoLogPolicy, AttributeNoRegistrationNeeded, AttributeOpenSource, AttributeMobileAppAvailable, AttributeNoJavaScriptNeeded}, ",")).
|
||||
SetTosHighlights(nil).
|
||||
Save(context.Background())
|
||||
|
||||
_, _ = Client.Service.Create().
|
||||
SetName("fixedfloat").
|
||||
SetLogoURL("https://kycnot.me/static/img/fixedfloat.webp").
|
||||
SetDescription("Instant, fully automatic cryptocurrency exchange with Lightning Network.").
|
||||
SetUrls([]string{"https://fixedfloat.com/"}).
|
||||
SetTosUrls([]string{"https://fixedfloat.com/terms-of-service"}).
|
||||
SetOnionUrls([]string{}).
|
||||
SetKycLevel(2).
|
||||
SetTags("swap,fast,no account").
|
||||
SetListingComments([]string{"This is a sample listing comment."}).
|
||||
SetPending(false).
|
||||
SetListed(true).
|
||||
SetVerified(false).
|
||||
SetXmr(true).
|
||||
SetBtc(true).
|
||||
SetLightning(true).
|
||||
SetFiat(false).
|
||||
SetCash(false).
|
||||
SetType(service.TypeExchange).
|
||||
SetCategory("").
|
||||
SetScore(6).
|
||||
SetAttributes(strings.Join([]string{AttributeRiskPreventionSystem, AttributeKYCIfObligedByLaw, AttributePrivateSourceCode, AttributeRefundRequiresKYC, AttributeNonCustodialWallet, AttributeNoRegistrationNeeded, AttributeAPIAvailable, AttributeJavaScriptNeeded}, ",")).
|
||||
SetTosHighlights(nil).
|
||||
Save(context.Background())
|
||||
|
||||
_, _ = Client.Service.Create().
|
||||
SetName("coinswap").
|
||||
SetLogoURL("https://kycnot.me/static/img/coinswap.webp").
|
||||
SetDescription("Simple and light swap page where you can swap various cryptos.").
|
||||
SetUrls([]string{"https://coinswap.click/"}).
|
||||
SetTosUrls([]string{"https://coinswap.click/faq/"}).
|
||||
SetOnionUrls([]string{}).
|
||||
SetKycLevel(1).
|
||||
SetTags("swap,fast,no account,nojs,light").
|
||||
SetPending(false).
|
||||
SetListed(true).
|
||||
SetVerified(true).
|
||||
SetXmr(true).
|
||||
SetBtc(true).
|
||||
SetLightning(true).
|
||||
SetFiat(false).
|
||||
SetCash(false).
|
||||
SetType(service.TypeExchange).
|
||||
SetCategory("").
|
||||
SetScore(8).
|
||||
SetAttributes(strings.Join([]string{AttributeKYCIfObligedByLaw, AttributePrivateSourceCode, AttributeRefundRequiresKYC, AttributeNonCustodialWallet, AttributeNoRegistrationNeeded, AttributeAPIAvailable, AttributeNoJavaScriptNeeded}, ",")).
|
||||
SetTosHighlights(nil).
|
||||
Save(context.Background())
|
||||
}
|
||||
func InitDb() {
|
||||
var err error
|
||||
|
||||
if os.Getenv("DB_TYPE") == "sqlite" {
|
||||
Client, err = ent.Open("sqlite3", "file:ent?mode=memory&cache=shared&_fk=1")
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("failed opening connection to sqlite: %v", err)
|
||||
}
|
||||
} else if os.Getenv("DB_TYPE") == "mysql" {
|
||||
Client, err = ent.Open("mysql", os.Getenv("DB_USER")+":"+os.Getenv("DB_PASS")+"@tcp("+os.Getenv("DB_HOST")+":"+os.Getenv("DB_PORT")+")/"+os.Getenv("DB_NAME"))
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("failed opening connection to mysql: %v", err)
|
||||
}
|
||||
} else if os.Getenv("DB_TYPE") == "postgres" {
|
||||
Client, err = ent.Open("postgres", "host="+os.Getenv("DB_HOST")+" port="+os.Getenv("DB_PORT")+" user="+os.Getenv("DB_USER")+" dbname="+os.Getenv("DB_NAME")+" password="+os.Getenv("DB_PASS")+" sslmode=disable")
|
||||
if err != nil {
|
||||
log.Fatal().Msgf("failed opening connection to postgres: %v", err)
|
||||
}
|
||||
} else {
|
||||
log.Fatal().Msgf("failed opening connection to database: %v", err)
|
||||
}
|
||||
if err := Client.Schema.Create(context.Background()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Run the auto migration tool.
|
||||
ctx := context.Background()
|
||||
if err := Client.Schema.Create(ctx); err != nil {
|
||||
log.Fatal().Msgf("failed creating schema resources: %v", err)
|
||||
}
|
||||
|
||||
if os.Getenv("DB_TYPE") == "sqlite" && config.Conf.Dev {
|
||||
log.Debug().Msg("Adding fake data to DB")
|
||||
AddFakeData()
|
||||
}
|
||||
}
|
||||
|
||||
func Close() {
|
||||
if err := Client.Close(); err != nil {
|
||||
log.Fatal().Msgf("failed closing database connection: %v", err)
|
||||
}
|
||||
}
|
53
src/database/models.go
Normal file
53
src/database/models.go
Normal file
|
@ -0,0 +1,53 @@
|
|||
package database
|
||||
|
||||
type Service struct {
|
||||
Category string `json:"category"`
|
||||
CollectionID string `json:"collectionId"`
|
||||
CollectionName string `json:"collectionName"`
|
||||
Comments []string `json:"comments"`
|
||||
Created string `json:"created"`
|
||||
Description string `json:"description"`
|
||||
Expand map[string][]AttributeNew `json:"expand"`
|
||||
Attributes []string `json:"attributes"`
|
||||
ID string `json:"id"`
|
||||
KycLevel int `json:"kyc_level"`
|
||||
Listed bool `json:"listed"`
|
||||
LogoURL string `json:"logo_url"`
|
||||
Name string `json:"name"`
|
||||
OnionUrls []string `json:"onion_urls"`
|
||||
Pending bool `json:"pending"`
|
||||
Score string `json:"score"`
|
||||
Tags []string `json:"tags"`
|
||||
TosReviews []TosReview `json:"tos_reviews"`
|
||||
LastTosReview string `json:"last_tos_review"`
|
||||
TosUrls []string `json:"tos_urls"`
|
||||
Type string `json:"type"`
|
||||
Referral string `json:"referral"`
|
||||
Updated string `json:"updated"`
|
||||
Urls []string `json:"urls"`
|
||||
Verified bool `json:"verified"`
|
||||
Xmr bool `json:"xmr"`
|
||||
Btc bool `json:"btc"`
|
||||
Fiat bool `json:"fiat"`
|
||||
Cash bool `json:"cash"`
|
||||
Lightning bool `json:"lightning"`
|
||||
}
|
||||
|
||||
type TosReview struct {
|
||||
Title string `json:"title"`
|
||||
Details string `json:"details"`
|
||||
Section string `json:"section"`
|
||||
Warning bool `json:"warning"`
|
||||
Reference string `json:"reference"`
|
||||
}
|
||||
|
||||
type AttributeNew struct {
|
||||
CollectionID string `json:"collectionId"`
|
||||
CollectionName string `json:"collectionName"`
|
||||
Created string `json:"created"`
|
||||
Description string `json:"description"`
|
||||
ID string `json:"id"`
|
||||
Rating string `json:"rating"`
|
||||
Title string `json:"title"`
|
||||
Updated string `json:"updated"`
|
||||
}
|
157
src/database/pocketbase.go
Normal file
157
src/database/pocketbase.go
Normal file
|
@ -0,0 +1,157 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/pluja/pocketbase"
|
||||
)
|
||||
|
||||
type PbClient struct {
|
||||
Client *pocketbase.Client
|
||||
}
|
||||
|
||||
var Pb *PbClient
|
||||
|
||||
// InitPocketbase initializes the Pocketbase client
|
||||
func InitPocketbase() error {
|
||||
// Initialize Pb if not already done
|
||||
if Pb == nil {
|
||||
Pb = &PbClient{}
|
||||
}
|
||||
|
||||
// Create a new pocketbase client
|
||||
Pb.Client = pocketbase.NewClient(os.Getenv("PB_URL"),
|
||||
pocketbase.WithAdminEmailPassword(os.Getenv("PB_ADMIN_EMAIL"), os.Getenv("PB_ADMIN_PASSWORD")))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetServices retrieves services from the pocketbase client
|
||||
func (p *PbClient) GetServices(filters, sort string) ([]Service, error) {
|
||||
|
||||
collection := pocketbase.CollectionSet[Service](p.Client, "services")
|
||||
params := pocketbase.ParamsList{
|
||||
Page: 1,
|
||||
Size: 200,
|
||||
Expand: "attributes",
|
||||
Fields: "*,expand.attributes.*",
|
||||
}
|
||||
|
||||
if filters != "" {
|
||||
params.Filters = filters
|
||||
}
|
||||
|
||||
if sort != "" {
|
||||
params.Sort = sort
|
||||
}
|
||||
|
||||
response, err := collection.List(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response.Items, nil
|
||||
}
|
||||
|
||||
func (p *PbClient) GetServiceByNameOrUrl(id string) (*Service, error) {
|
||||
collection := pocketbase.CollectionSet[Service](p.Client, "services")
|
||||
params := pocketbase.ParamsList{
|
||||
Page: 1,
|
||||
Size: 1,
|
||||
Fields: "*,expand.attributes.*",
|
||||
Expand: "attributes",
|
||||
Filters: fmt.Sprintf("((name='%v') || (urls~'%v'))", id, id),
|
||||
}
|
||||
|
||||
// TODO: Sort attributes by rating
|
||||
|
||||
response, err := collection.List(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response.Items[0], nil
|
||||
}
|
||||
|
||||
func (p *PbClient) GetServiceById(id string) (*Service, error) {
|
||||
collection := pocketbase.CollectionSet[Service](p.Client, "services")
|
||||
params := pocketbase.ParamsList{
|
||||
Fields: "*,expand.attributes.*",
|
||||
Expand: "attributes",
|
||||
}
|
||||
|
||||
response, err := collection.OneWithParams(id, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (p *PbClient) CreateService(service Service) error {
|
||||
collection := pocketbase.CollectionSet[Service](p.Client, "services")
|
||||
|
||||
_, err := collection.Create(service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PbClient) UpdateService(id string, service Service) error {
|
||||
collection := pocketbase.CollectionSet[Service](p.Client, "services")
|
||||
|
||||
err := collection.Update(id, service)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PbClient) GetAttribute(id string) (*AttributeNew, error) {
|
||||
collection := pocketbase.CollectionSet[AttributeNew](p.Client, "attributes")
|
||||
|
||||
response, err := collection.One(id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
func (p *PbClient) GetAttributes(filters, sort string) ([]AttributeNew, error) {
|
||||
collection := pocketbase.CollectionSet[AttributeNew](p.Client, "attributes")
|
||||
params := pocketbase.ParamsList{
|
||||
Page: 1,
|
||||
Size: 250,
|
||||
}
|
||||
|
||||
if filters != "" {
|
||||
params.Filters = filters
|
||||
}
|
||||
|
||||
if sort != "" {
|
||||
params.Sort = sort
|
||||
}
|
||||
|
||||
response, err := collection.List(params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return response.Items, nil
|
||||
}
|
||||
|
||||
func (p *PbClient) CreateAttribute(attribute AttributeNew) error {
|
||||
collection := pocketbase.CollectionSet[AttributeNew](p.Client, "attributes")
|
||||
|
||||
_, err := collection.Create(attribute)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue