├── .dockerignore ├── .github ├── FUNDING.yml └── workflows │ └── docker-image.yaml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── cache ├── cache.go └── cache_test.go ├── docs ├── brokenStuff.md ├── buildingFromSource.md ├── index.html ├── migrationGuide.md └── openapi.json ├── go.mod ├── go.sum ├── handlers ├── ListenAndServe.go ├── catchall.go ├── getAdventurer.go ├── getAdventurerSearch.go ├── getCache.go ├── getGuild.go ├── getGuildSearch.go ├── getStatus.go ├── giveBadRequestResponse.go └── giveMaintenanceResponse.go ├── logger ├── Log.go └── logger.go ├── main.go ├── middleware ├── CreateStack.go ├── GetRateLimitMiddleware.go └── GetSetHeadersMiddleware.go ├── models ├── Character.go ├── GuildProfile.go ├── History.go ├── Mastery.go ├── Profile.go └── Specs.go ├── scraper ├── GetCloseTime.go ├── extractProfileTarget.go ├── scrapeAdventurer.go ├── scrapeAdventurerSearch.go ├── scrapeGuild.go ├── scrapeGuildSearch.go ├── scraper.go └── taskQueue.go ├── translators ├── TranslateClassName.go ├── TranslateMisc.go └── TranslateSpecLevel.go ├── utils ├── BuildRequest.go ├── BuildRequest_test.go ├── CalculateCombatFame.go ├── CalculateLifeFame.go ├── CalculateLifeFame_test.go ├── FormatDateForHeaders.go ├── FormatDateForHeaders_test.go ├── ParseDate.go └── ParseDate_test.go └── validators ├── ValidateAdventurerNameQueryParam.go ├── ValidateAdventurerNameQueryParam_test.go ├── ValidateGuildNameQueryParam.go ├── ValidateGuildNameQueryParam_test.go ├── ValidateProfileTargetQueryParam.go ├── ValidateProfileTargetQueryParam_test.go ├── ValidateRegionQueryParam.go ├── ValidateRegionQueryParam_test.go ├── ValidateSearchTypeQueryParam.go └── ValidateSearchTypeQueryParam_test.go /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .gitignore 3 | *_test.go 4 | /doc 5 | Dockerfile 6 | LICENSE 7 | Procfile 8 | README.md 9 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: man90es 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: man90 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | polar: # Replace with a single Polar username 14 | custom: https://www.hemlo.cc/finances#donate 15 | -------------------------------------------------------------------------------- /.github/workflows/docker-image.yaml: -------------------------------------------------------------------------------- 1 | name: Publish Docker image 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | push_to_registry: 9 | name: Push Docker image to Docker Hub 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Check out the repo 13 | uses: actions/checkout@v3 14 | 15 | - name: Log in to Docker Hub 16 | uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a 17 | with: 18 | username: ${{ secrets.DOCKER_USERNAME }} 19 | password: ${{ secrets.DOCKER_PASSWORD }} 20 | 21 | - name: Extract metadata (tags, labels) for Docker 22 | id: meta 23 | uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 24 | with: 25 | images: man90/bdo-rest-api 26 | 27 | - name: Build and push Docker image 28 | uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 29 | with: 30 | context: . 31 | file: ./Dockerfile 32 | push: true 33 | tags: ${{ steps.meta.outputs.tags }} 34 | labels: ${{ steps.meta.outputs.labels }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bdo-rest-api 2 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.24-alpine AS build 2 | RUN apk add --no-cache git 3 | WORKDIR /src/bdo-rest-api 4 | COPY . . 5 | RUN go mod download 6 | RUN go build -o /bdo-rest-api -ldflags="-s -w" . 7 | 8 | FROM alpine:3.14 AS bin 9 | RUN addgroup --system --gid 1001 go 10 | RUN adduser --system --uid 1001 go 11 | COPY --from=build --chown=go:go /bdo-rest-api . 12 | USER go 13 | ENV PROXY= 14 | EXPOSE 8001 15 | ENTRYPOINT ["/bdo-rest-api"] 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 man90 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BDO-REST-API 2 | Scraper for Black Desert Online community data with a built-in API server. It currently supports EU, NA, SA and KR regions. 3 | 4 | ## Projects using this API 5 | - BDO Leaderboards ([Website](https://bdo.hemlo.cc/leaderboards), [sources](https://github.com/man90es/BDO-Leaderboards)): web-based leaderboards for Black Desert Online. 6 | - Ikusa ([Website](https://ikusa.site), [sources](https://github.com/sch-28/ikusa_api)): powerful tool that allows you to analyze your game logs and gain valuable insights into your combat performance. 7 | - GuildYapper ([Discord server](https://discord.gg/x2nKYuu2Z2)): Discord bot with various features for BDO guilds such as guild and player history logging, and automatic trial Discord management (more features TBA). 8 | - BDO Guild Bosses - Alliance [EU] ([Discord server](https://discord.gg/735bYrQWKr)): Discord bot for organising events in a guild bosses alliance. 9 | - Cute Papus! ([Website](https://cutepap.us/)): A collection of various BDO-related tools in a single web app. 10 | 11 | ## How to start using it 12 | There are two ways to use this scraper for your needs: 13 | * By querying https://bdo.hemlo.cc/communityapi/v1 — this is the "official" instance hosted by me. 14 | * If you want to have more control over the API, host the scraper yourself using one of the following methods: 15 | - As a Docker container: the image is available on [DockerHub](https://hub.docker.com/r/man90/bdo-rest-api). 16 | - Natively: build the binary from source as described in [this guide](docs/buildingFromSource.md). 17 | 18 | API documentation can be viewed [here](https://man90es.github.io/BDO-REST-API/). 19 | 20 | ## Flags 21 | If you host the API yourself, either via Docker or natively, you can control some of its features by executing it with flags. 22 | 23 | Available flags: 24 | - `-cachettl` 25 | - Specifies cache TTL in minutes 26 | - Type: unsigned integer 27 | - Default value: `180` 28 | - `-maintenancettl` 29 | - Limits how frequently scraper can check for maintenance end in minutes 30 | - Type: unsigned integer 31 | - Default value: `5` 32 | - `-maxtasksperclient` 33 | - Limits the number of concurrent scraping tasks that can be executed per client 34 | - Type: unsigned integer 35 | - Default value: `5` 36 | - `-port` 37 | - Specifies API server's port 38 | - Type: unsigned integer 39 | - Default value: `8001` 40 | - Also available as `PORT` environment variable (doesn't work in Docker) 41 | - `-proxy` 42 | - Specifies a list of proxies to make requests to BDO servers through 43 | - Type: string, space-separated list of IP addresses or URLs 44 | - Default value: none, requests are made directly 45 | - Also available as `PROXY` environment variable 46 | - `-ratelimit` 47 | - Sets the maximum number of requests per minute per IP address 48 | - Type: unsigned integer 49 | - Default value: 512 50 | - `-taskretries` 51 | - Specifies the number of retries for a scraping task 52 | - Type: unsigned integer 53 | - Default value: `3` 54 | - `-verbose` 55 | - Allows to put the app into verbose mode and print out additional logs to stdout 56 | - Default value: none, no additional output is produced 57 | 58 | You can use them like this: 59 | ```bash 60 | ./bdo-rest-api -cachettl 30 61 | # or 62 | docker container run -p 8001:8001 bdo-rest-api -cachettl 30 63 | ``` 64 | 65 | ## Contributing 66 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 67 | 68 | ## Known bugs 69 | There is a number of bugs that the official BDO website has. This scraper does not do anything about them for the sake of simplicity, so your apps may need to use [workarounds](docs/brokenStuff.md). 70 | 71 | ## By the way 72 | This is a fan-created project that is not affiliated with or endorsed by Pearl Abyss. 73 | -------------------------------------------------------------------------------- /cache/cache.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "strings" 5 | "time" 6 | 7 | goCache "github.com/patrickmn/go-cache" 8 | "github.com/spf13/viper" 9 | messagebus "github.com/vardius/message-bus" 10 | "golang.org/x/exp/maps" 11 | 12 | "bdo-rest-api/models" 13 | "bdo-rest-api/utils" 14 | ) 15 | 16 | type CacheEntry[T any] struct { 17 | Data T 18 | Date time.Time 19 | Status int 20 | } 21 | 22 | type cache[T any] struct { 23 | Bus messagebus.MessageBus 24 | internalCache *goCache.Cache 25 | } 26 | 27 | func joinKeys(keys []string) string { 28 | return strings.Join(keys, ",") 29 | } 30 | 31 | func newCache[T any]() *cache[T] { 32 | cacheTTL := viper.GetDuration("cachettl") 33 | 34 | return &cache[T]{ 35 | Bus: messagebus.New(100), // Idk what buffer size is optimal 36 | internalCache: goCache.New(cacheTTL, min(time.Hour, cacheTTL)), 37 | } 38 | } 39 | 40 | func (c *cache[T]) AddRecord(keys []string, data T, status int, taskId string) (date string, expires string) { 41 | cacheTTL := viper.GetDuration("cachettl") 42 | entry := CacheEntry[T]{ 43 | Data: data, 44 | Date: time.Now(), 45 | Status: status, 46 | } 47 | 48 | c.internalCache.Add(joinKeys(keys), entry, cacheTTL) 49 | c.Bus.Publish(taskId, entry) 50 | 51 | return utils.FormatDateForHeaders(entry.Date), utils.FormatDateForHeaders(entry.Date.Add(cacheTTL)) 52 | } 53 | 54 | func (c *cache[T]) GetRecord(keys []string) (data T, status int, date string, expires string, found bool) { 55 | cacheTTL := viper.GetDuration("cachettl") 56 | anyEntry, found := c.internalCache.Get(joinKeys(keys)) 57 | 58 | if !found { 59 | return 60 | } 61 | 62 | entry := anyEntry.(CacheEntry[T]) 63 | 64 | return entry.Data, entry.Status, utils.FormatDateForHeaders(entry.Date), utils.FormatDateForHeaders(entry.Date.Add(cacheTTL)), found 65 | } 66 | 67 | func (c *cache[T]) GetItemCount() int { 68 | return c.internalCache.ItemCount() 69 | } 70 | 71 | func (c *cache[T]) GetKeys() []string { 72 | return maps.Keys(c.internalCache.Items()) 73 | } 74 | 75 | var GuildProfiles = newCache[models.GuildProfile]() 76 | var GuildSearch = newCache[[]models.GuildProfile]() 77 | var Profiles = newCache[models.Profile]() 78 | var ProfileSearch = newCache[[]models.Profile]() 79 | -------------------------------------------------------------------------------- /cache/cache_test.go: -------------------------------------------------------------------------------- 1 | package cache 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | 7 | "github.com/spf13/viper" 8 | ) 9 | 10 | func init() { 11 | viper.Set("cachettl", time.Second) 12 | } 13 | 14 | func TestCache(t *testing.T) { 15 | // Create a cache instance for testing 16 | testCache := newCache[string]() 17 | 18 | // Test AddRecord and GetRecord 19 | keys := []string{"key1", "key2"} 20 | data := "test data" 21 | status := 200 22 | taskId := "task-id" 23 | 24 | date, expires := testCache.AddRecord(keys, data, status, taskId) 25 | 26 | // Validate AddRecord results 27 | if date == "" || expires == "" { 28 | t.Error("AddRecord should return non-empty date and expires values") 29 | } 30 | 31 | // Test GetRecord for an existing record 32 | returnedData, returnedStatus, returnedDate, returnedExpires, found := testCache.GetRecord(keys) 33 | 34 | if !found { 35 | t.Error("GetRecord should find the record") 36 | } 37 | 38 | // Validate GetRecord results 39 | if returnedData != data || returnedStatus != status || returnedDate == "" || returnedExpires == "" { 40 | t.Error("GetRecord returned unexpected values") 41 | } 42 | 43 | // Test GetItemCount 44 | itemCount := testCache.GetItemCount() 45 | if itemCount != 1 { 46 | t.Errorf("GetItemCount should return 1, but got %d", itemCount) 47 | } 48 | 49 | // Sleep for a while to allow the cache entry to expire 50 | time.Sleep(2 * time.Second) 51 | 52 | // Test GetRecord for an expired record 53 | _, _, _, _, found = testCache.GetRecord(keys) 54 | 55 | if found { 56 | t.Error("GetRecord should not find an expired record") 57 | } 58 | 59 | // Test GetItemCount after expiration 60 | itemCount = testCache.GetItemCount() 61 | if itemCount != 0 { 62 | t.Errorf("GetItemCount should return 0 after expiration, but got %d", itemCount) 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /docs/brokenStuff.md: -------------------------------------------------------------------------------- 1 | # Broken Stuff 2 | BDO website, where all the data is taken from, has a number of bugs, which affects by this API by design and, sadly, not much can be done about it. 3 | 4 | ## List of known bugs 5 | This is a list of bugs that either used to occur that I'm aware of. They may be still occuring or be fixed. 6 | 7 | ### 🐞 Data is not updated immediately after it is updated in game 8 | The website's lag is around a few hours, and you can only wait. This API introduces additional lag that depends on the cache TTL parameter. 9 | 10 | ### 🐞 Members who left the guild remain on the guild members' list for some time 11 | I believe maintenances remove "ghost members" from guilds. If you don't feel like waiting, request profiles of those players. Guild membership status in player profiles is more reliable, unless it's set to private. 12 | 13 | ### 🐞 Profile of a different guild is returned instead of the one requested 14 | Always check if the guild profile in response has the same name you specified. Also see next bug. 15 | 16 | ### 🐞 Guild profile returned as "Not Found" although the guild exists in the game 17 | You can get some information like creation date, guild master's name and population by searching for guild instead of requesting its profile. It's not much, but better than nothing. 18 | 19 | ### 🐞 Player profile returned as "Not Found" although that player exists in the game 20 | There are no known workarounds. [See issue #5](https://github.com/man90es/BDO-REST-API/issues/5). 21 | 22 | ### 🐞 Players whose family name is longer than 16 characters aren't searchable 23 | Family names longer than 16 characters aren't officially allowed in BDO, but there may be a bug that allows players to take them. [See issue #13](https://github.com/man90es/BDO-REST-API/issues/13). This API won't support them unless there will be many reports of players with long family names. 24 | 25 | ### 🐞 Some guild members are missing when requesting a guild profile 26 | BDO website hides some guild members on its website based on unknown conditions. Supposedly, all hidden members are alt accounts with zero progress on the account. 27 | 28 | ### 🐞 The number of guild members when searching for a guild doesn't match the number of guild members when requesting the guild profile 29 | See the previous bug on the list. The number when searching is the correct one. 30 | 31 | ## Contribute to this list 32 | If you found a bug on the original BDO website that affects this API and is not listed in this file, you can contribute by either: 33 | - making a pull request or creating an issue [on GitHub](https://github.com/man90es/BDO-REST-API) 34 | - using one of the contact methods listed [on my website](https://www.hemlo.cc/) 35 | -------------------------------------------------------------------------------- /docs/buildingFromSource.md: -------------------------------------------------------------------------------- 1 | # Building from source 2 | Building the scraper from source may be preferable in some cases. This way, the app has a smaller footprint than a [Docker image](https://hub.docker.com/r/man90/bdo-rest-api). 3 | 4 | ## Prerequisites: 5 | - GNU/Linux (other platforms should work as well but I haven't tested them) 6 | - Go compiler >=v1.21 7 | 8 | ## Compilation 9 | Use this command to compile the app: 10 | ```bash 11 | go build 12 | ``` 13 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | BDO-REST-API documentation 4 | 5 | 6 | 7 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /docs/migrationGuide.md: -------------------------------------------------------------------------------- 1 | # Migration guide 2 | Version v0 of this API is no longer supported and is not fully functional due to changes in the official BDO website. This guide explains how to migrate an application designed to work with v0 of this API to using v1 instead. 3 | 4 | ## API paths 5 | All available API paths got renamed to follow the REST standards more closely: 6 | 7 | | Previously (v0) | Now (v1) | 8 | | ---------------------- | --------------------- | 9 | | /v0/profile | /v1/adventurer | 10 | | /v0/profileSearch | /v1/adventurer/search | 11 | | /v0/guildProfile | /v1/guild | 12 | | /v0/guildProfileSearch | /v1/guild/search | 13 | 14 | ## Redundant data 15 | There was some tautology in the v0 responses. Hence, some attributes got removed/renamed in v1: 16 | 17 | ### GET /v1/adventurer 18 | - `response.guild.region` got removed, use `response.region` instead. 19 | 20 | ### GET /v1/adventurer/search 21 | - `response[i].guild.region` got removed, use `response[i].region` instead. 22 | 23 | ### GET /v1/guild 24 | - `response.guildMaster.region` got removed, use `response.region` instead. 25 | - `response.guildMaster` got renamed into `response.master`. 26 | 27 | ### GET /v1/guild/search 28 | - `response[i].guildMaster.region` got removed, use `response[i].region` instead. 29 | - `response[i].guildMaster` got renamed into `response[i].master`. 30 | 31 | ## Error handling 32 | v0 didn't have a single error communication standard, so applications using it didn't have a reliable way to handle them. With v1, you can always rely on the response [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status). Codes that are currently in use: 33 | | Status | Meaning | 34 | | ----------------------- | ---------------------------------------------------------- | 35 | | 200 OK | Enjoy your data | 36 | | 400 Bad Request | Some required request parameters are missing | 37 | | 404 Not Found | The data you requested is not available on the BDO website | 38 | | 503 Service Unavailable | BDO servers are currently under maintenance | 39 | -------------------------------------------------------------------------------- /docs/openapi.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0.2", 3 | "info": { 4 | "title": "BDO REST API", 5 | "version": "v1" 6 | }, 7 | "servers": [ 8 | { 9 | "url": "https://bdo.hemlo.cc/communityapi" 10 | }, 11 | { 12 | "url": "http://localhost:8001" 13 | } 14 | ], 15 | "components": { 16 | "parameters": { 17 | "region": { 18 | "name": "region", 19 | "in": "query", 20 | "schema": { 21 | "type": "string", 22 | "enum": [ 23 | "EU", 24 | "KR", 25 | "NA", 26 | "SA" 27 | ], 28 | "default": "EU" 29 | } 30 | } 31 | }, 32 | "responses": { 33 | "202": { 34 | "description": "Data is being fetched. Please try again later." 35 | }, 36 | "400": { 37 | "description": "Bad Request. A required query parameter is either missing or in a wrong format." 38 | }, 39 | "404": { 40 | "description": "Not Found. Request something else, or contact instance owner if you're sure that it's a mistake." 41 | }, 42 | "429": { 43 | "description": "Too Many Requests. Try doing the same request after waiting some time." 44 | }, 45 | "500": { 46 | "description": "Internal Server Error. Try doing the same request after waiting some time, contact instance owner if the problem persists." 47 | }, 48 | "503": { 49 | "description": "Service Unavailable. BDO website is currently under maintenance and requested data is temporarily not available." 50 | } 51 | } 52 | }, 53 | "paths": { 54 | "/v1": { 55 | "get": { 56 | "summary": "Retrieve instance's status", 57 | "operationId": "getMeta", 58 | "responses": { 59 | "200": { 60 | "description": "OK.", 61 | "headers": { 62 | "Date": { 63 | "description": "Date and time of when the request was processed.", 64 | "schema": { 65 | "type": "string", 66 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 67 | } 68 | }, 69 | "X-Ratelimit-Limit": { 70 | "description": "Maximum number of requests per minute per IP address.", 71 | "schema": { 72 | "type": "integer", 73 | "example": 512 74 | } 75 | }, 76 | "X-Ratelimit-Remaining": { 77 | "description": "Number of requests left for your IP address for the current minute.", 78 | "schema": { 79 | "type": "integer", 80 | "example": 256 81 | } 82 | }, 83 | "X-Ratelimit-Reset": { 84 | "description": "Timestamp of the next minute, when rate limit resets.", 85 | "schema": { 86 | "type": "integer", 87 | "example": 1746433664 88 | } 89 | } 90 | }, 91 | "content": { 92 | "application/json": { 93 | "schema": { 94 | "type": "object", 95 | "properties": { 96 | "cache": { 97 | "type": "object", 98 | "properties": { 99 | "lastDetectedMaintenance": { 100 | "type": "object", 101 | "example": { 102 | "EU": "0001-01-01T00:00:00Z", 103 | "KR": "0001-01-01T00:00:00Z", 104 | "NA": "0001-01-01T00:00:00Z", 105 | "SA": "0001-01-01T00:00:00Z" 106 | } 107 | }, 108 | "responses": { 109 | "type": "object", 110 | "properties": { 111 | "/adventurer": { 112 | "type": "number" 113 | }, 114 | "/adventurer/search": { 115 | "type": "number" 116 | }, 117 | "/guild": { 118 | "type": "number" 119 | }, 120 | "/guild/search": { 121 | "type": "number" 122 | } 123 | } 124 | }, 125 | "ttl": { 126 | "type": "object", 127 | "properties": { 128 | "general": { 129 | "type": "string", 130 | "default": "3h0m0s" 131 | }, 132 | "maintenanceStatus": { 133 | "type": "string", 134 | "default": "5m0s" 135 | } 136 | } 137 | } 138 | } 139 | }, 140 | "docs": { 141 | "type": "string", 142 | "default": "https://man90es.github.io/BDO-REST-API" 143 | }, 144 | "proxies": { 145 | "type": "number" 146 | }, 147 | "rateLimit": { 148 | "type": "number", 149 | "default": 512 150 | }, 151 | "taskQueue": { 152 | "type": "object", 153 | "properties": { 154 | "maxTasksPerClient": { 155 | "type": "number", 156 | "default": 5 157 | }, 158 | "taskRetries": { 159 | "type": "number", 160 | "default": 3 161 | } 162 | } 163 | }, 164 | "uptime": { 165 | "type": "string", 166 | "example": "2m49s" 167 | }, 168 | "version": { 169 | "type": "string", 170 | "example": "1.5.1" 171 | } 172 | } 173 | } 174 | } 175 | } 176 | } 177 | } 178 | } 179 | }, 180 | "/v1/adventurer": { 181 | "get": { 182 | "summary": "Retrieve player's profile.", 183 | "description": "Retrieve the full profile of a single player by his or her profileTarget.", 184 | "operationId": "getAdventurer", 185 | "parameters": [ 186 | { 187 | "name": "profileTarget", 188 | "in": "query", 189 | "description": "Player's profileTarget. It should be at least 150 characters long. You can get it from the guild members' list or from the search.", 190 | "required": true, 191 | "schema": { 192 | "type": "string" 193 | } 194 | }, 195 | { 196 | "name": "region", 197 | "in": "query", 198 | "description": "Can be omitted for EU or NA. Providing NA as the value can return EU profiles and vice versa.", 199 | "schema": { 200 | "type": "string", 201 | "enum": [ 202 | "EU", 203 | "KR", 204 | "NA", 205 | "SA" 206 | ], 207 | "default": "EU" 208 | } 209 | } 210 | ], 211 | "responses": { 212 | "200": { 213 | "description": "OK.", 214 | "headers": { 215 | "Date": { 216 | "description": "Date and time of when the request was processed.", 217 | "schema": { 218 | "type": "string", 219 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 220 | } 221 | }, 222 | "Expires": { 223 | "description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.", 224 | "schema": { 225 | "type": "string", 226 | "example": "Thu, 01 Jan 1970 03:00:00 GMT" 227 | } 228 | }, 229 | "Last-Modified": { 230 | "description": "Date and time when the scraper fetched the data.", 231 | "schema": { 232 | "type": "string", 233 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 234 | } 235 | }, 236 | "X-Ratelimit-Limit": { 237 | "description": "Maximum number of requests per minute per IP address.", 238 | "schema": { 239 | "type": "integer", 240 | "example": 512 241 | } 242 | }, 243 | "X-Ratelimit-Remaining": { 244 | "description": "Number of requests left for your IP address for the current minute.", 245 | "schema": { 246 | "type": "integer", 247 | "example": 256 248 | } 249 | }, 250 | "X-Ratelimit-Reset": { 251 | "description": "Timestamp of the next minute, when rate limit resets.", 252 | "schema": { 253 | "type": "integer", 254 | "example": 1746433664 255 | } 256 | } 257 | }, 258 | "content": { 259 | "application/json": { 260 | "schema": { 261 | "title": "Profile", 262 | "type": "object", 263 | "properties": { 264 | "familyName": { 265 | "nullable": false, 266 | "type": "string", 267 | "example": "Apple" 268 | }, 269 | "profileTarget": { 270 | "nullable": false, 271 | "type": "string", 272 | "example": "XXX" 273 | }, 274 | "region": { 275 | "nullable": false, 276 | "type": "string", 277 | "enum": [ 278 | "EU", 279 | "KR", 280 | "NA", 281 | "SA" 282 | ] 283 | }, 284 | "guild": { 285 | "nullable": true, 286 | "properties": { 287 | "name": { 288 | "nullable": false, 289 | "type": "string", 290 | "example": "TumblrGirls" 291 | } 292 | } 293 | }, 294 | "contributionPoints": { 295 | "description": "Contribution points", 296 | "nullable": true, 297 | "type": "integer", 298 | "example": 100, 299 | "minimum": 0 300 | }, 301 | "createdOn": { 302 | "description": "Account creation date", 303 | "nullable": false, 304 | "type": "string", 305 | "example": "2020-02-23T00:00:00Z" 306 | }, 307 | "characters": { 308 | "description": "Player's characters", 309 | "type": "array", 310 | "nullable": false, 311 | "items": { 312 | "type": "object", 313 | "properties": { 314 | "name": { 315 | "nullable": false, 316 | "type": "string", 317 | "example": "Blue" 318 | }, 319 | "class": { 320 | "nullable": false, 321 | "type": "string", 322 | "example": "Ninja" 323 | }, 324 | "main": { 325 | "nullable": true, 326 | "type": "boolean", 327 | "example": true 328 | }, 329 | "level": { 330 | "nullable": true, 331 | "type": "integer", 332 | "example": 56, 333 | "minimum": 0 334 | } 335 | } 336 | } 337 | }, 338 | "specLevels": { 339 | "description": "Levels of different life skills", 340 | "nullable": true, 341 | "properties": { 342 | "gathering": { 343 | "nullable": false, 344 | "type": "string", 345 | "example": "Beginner 6" 346 | }, 347 | "fishing": { 348 | "nullable": false, 349 | "type": "string", 350 | "example": "Master 18" 351 | }, 352 | "hunting": { 353 | "nullable": false, 354 | "type": "string", 355 | "example": "Beginner 1" 356 | }, 357 | "cooking": { 358 | "nullable": false, 359 | "type": "string", 360 | "example": "Beginner 4" 361 | }, 362 | "alchemy": { 363 | "nullable": false, 364 | "type": "string", 365 | "example": "Beginner 1" 366 | }, 367 | "processing": { 368 | "nullable": false, 369 | "type": "string", 370 | "example": "Beginner 9" 371 | }, 372 | "training": { 373 | "nullable": false, 374 | "type": "string", 375 | "example": "Apprentice 1" 376 | }, 377 | "trading": { 378 | "nullable": false, 379 | "type": "string", 380 | "example": "Apprentice 3" 381 | }, 382 | "farming": { 383 | "nullable": false, 384 | "type": "string", 385 | "example": "Beginner 1" 386 | }, 387 | "sailing": { 388 | "nullable": false, 389 | "type": "string", 390 | "example": "Beginner 1" 391 | }, 392 | "barter": { 393 | "nullable": false, 394 | "type": "string", 395 | "example": "Beginner 1" 396 | } 397 | } 398 | }, 399 | "lifeFame": { 400 | "description": "Life fame", 401 | "example": 907, 402 | "nullable": true, 403 | "type": "integer", 404 | "minimum": 0 405 | }, 406 | "combatFame": { 407 | "description": "Combat fame", 408 | "example": 1136, 409 | "nullable": true, 410 | "type": "integer", 411 | "minimum": 0 412 | }, 413 | "energy": { 414 | "description": "Energy", 415 | "example": 400, 416 | "nullable": true, 417 | "type": "integer", 418 | "minimum": 0 419 | }, 420 | "gs": { 421 | "description": "The higher value between AP+DP or AAP+DP.", 422 | "example": 600, 423 | "nullable": true, 424 | "type": "integer", 425 | "minimum": 0 426 | }, 427 | "history": { 428 | "description": "30-day history of the adventurer's activity", 429 | "nullable": true, 430 | "type": "object", 431 | "properties": { 432 | "fish": { 433 | "description": "Fished items", 434 | "nullable": false, 435 | "type": "integer", 436 | "example": 100, 437 | "minimum": 0 438 | }, 439 | "loot": { 440 | "description": "Obtained loot", 441 | "nullable": false, 442 | "type": "integer", 443 | "example": 200, 444 | "minimum": 0 445 | }, 446 | "lootWeight": { 447 | "description": "Obtained loot weight", 448 | "nullable": false, 449 | "type": "integer", 450 | "example": 300, 451 | "minimum": 0 452 | }, 453 | "mobs": { 454 | "description": "Monsters defeated", 455 | "nullable": false, 456 | "type": "number", 457 | "example": 400, 458 | "minimum": 0 459 | } 460 | } 461 | }, 462 | "mastery": { 463 | "description": "Mastery of different life skills", 464 | "nullable": true, 465 | "properties": { 466 | "gathering": { 467 | "nullable": false, 468 | "type": "integer", 469 | "example": 1000, 470 | "minimum": 0 471 | }, 472 | "fishing": { 473 | "nullable": false, 474 | "type": "integer", 475 | "example": 1000, 476 | "minimum": 0 477 | }, 478 | "hunting": { 479 | "nullable": false, 480 | "type": "integer", 481 | "example": 1000, 482 | "minimum": 0 483 | }, 484 | "cooking": { 485 | "nullable": false, 486 | "type": "integer", 487 | "example": 1000, 488 | "minimum": 0 489 | }, 490 | "alchemy": { 491 | "nullable": false, 492 | "type": "integer", 493 | "example": 1000, 494 | "minimum": 0 495 | }, 496 | "processing": { 497 | "nullable": false, 498 | "type": "integer", 499 | "example": 1000, 500 | "minimum": 0 501 | }, 502 | "training": { 503 | "nullable": false, 504 | "type": "integer", 505 | "example": 1000, 506 | "minimum": 0 507 | }, 508 | "trading": { 509 | "nullable": false, 510 | "type": "integer", 511 | "example": 1000, 512 | "minimum": 0 513 | }, 514 | "farming": { 515 | "nullable": false, 516 | "type": "integer", 517 | "example": 1000, 518 | "minimum": 0 519 | }, 520 | "sailing": { 521 | "nullable": false, 522 | "type": "integer", 523 | "example": 1000, 524 | "minimum": 0 525 | }, 526 | "barter": { 527 | "nullable": false, 528 | "type": "integer", 529 | "example": 1000, 530 | "minimum": 0 531 | } 532 | } 533 | }, 534 | "privacy": { 535 | "description": "Player's privacy level. Can be either 0 for public or 15 for private.", 536 | "nullable": true, 537 | "type": "integer" 538 | } 539 | } 540 | } 541 | } 542 | } 543 | }, 544 | "202": { 545 | "$ref": "#/components/responses/202" 546 | }, 547 | "400": { 548 | "$ref": "#/components/responses/400" 549 | }, 550 | "404": { 551 | "$ref": "#/components/responses/404" 552 | }, 553 | "429": { 554 | "$ref": "#/components/responses/429" 555 | }, 556 | "500": { 557 | "$ref": "#/components/responses/500" 558 | }, 559 | "503": { 560 | "$ref": "#/components/responses/503" 561 | } 562 | } 563 | } 564 | }, 565 | "/v1/adventurer/search": { 566 | "get": { 567 | "summary": "Search for a player.", 568 | "description": "Search for a player by a combination of his or her region and family/character name.", 569 | "operationId": "getAdventurerSearch", 570 | "parameters": [ 571 | { 572 | "name": "query", 573 | "in": "query", 574 | "description": "Only exact matches work for this search. The length of this parameter should be between 3 and 16 characters, and you can only use symbols A-Z, a-z, 0-9, _.", 575 | "required": true, 576 | "schema": { 577 | "type": "string" 578 | } 579 | }, 580 | { 581 | "$ref": "#/components/parameters/region" 582 | }, 583 | { 584 | "name": "searchType", 585 | "in": "query", 586 | "description": "Switch between filtering by family name and character name. If you omit this parameter, it's assumed that you want to filter by family name.", 587 | "schema": { 588 | "type": "string", 589 | "enum": [ 590 | "familyName", 591 | "characterName" 592 | ], 593 | "example": "familyName" 594 | } 595 | } 596 | ], 597 | "responses": { 598 | "200": { 599 | "description": "OK.", 600 | "headers": { 601 | "Date": { 602 | "description": "Date and time of when the request was processed.", 603 | "schema": { 604 | "type": "string", 605 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 606 | } 607 | }, 608 | "Expires": { 609 | "description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.", 610 | "schema": { 611 | "type": "string", 612 | "example": "Thu, 01 Jan 1970 03:00:00 GMT" 613 | } 614 | }, 615 | "Last-Modified": { 616 | "description": "Date and time when the scraper fetched the data.", 617 | "schema": { 618 | "type": "string", 619 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 620 | } 621 | }, 622 | "X-Ratelimit-Limit": { 623 | "description": "Maximum number of requests per minute per IP address.", 624 | "schema": { 625 | "type": "integer", 626 | "example": 512 627 | } 628 | }, 629 | "X-Ratelimit-Remaining": { 630 | "description": "Number of requests left for your IP address for the current minute.", 631 | "schema": { 632 | "type": "integer", 633 | "example": 256 634 | } 635 | }, 636 | "X-Ratelimit-Reset": { 637 | "description": "Timestamp of the next minute, when rate limit resets.", 638 | "schema": { 639 | "type": "integer", 640 | "example": 1746433664 641 | } 642 | } 643 | }, 644 | "content": { 645 | "application/json": { 646 | "schema": { 647 | "title": "Profile", 648 | "type": "array", 649 | "items": { 650 | "type": "object", 651 | "properties": { 652 | "familyName": { 653 | "nullable": false, 654 | "type": "string", 655 | "example": "Apple" 656 | }, 657 | "profileTarget": { 658 | "nullable": false, 659 | "type": "string", 660 | "example": "XXX" 661 | }, 662 | "region": { 663 | "nullable": false, 664 | "type": "string", 665 | "enum": [ 666 | "EU", 667 | "KR", 668 | "NA", 669 | "SA" 670 | ] 671 | }, 672 | "guild": { 673 | "nullable": true, 674 | "properties": { 675 | "name": { 676 | "nullable": false, 677 | "type": "string", 678 | "example": "TumblrGirls" 679 | } 680 | } 681 | }, 682 | "characters": { 683 | "nullable": true, 684 | "type": "array", 685 | "items": { 686 | "type": "object", 687 | "properties": { 688 | "name": { 689 | "nullable": false, 690 | "type": "string", 691 | "example": "Blue" 692 | }, 693 | "class": { 694 | "nullable": false, 695 | "type": "string", 696 | "example": "Ninja" 697 | }, 698 | "main": { 699 | "nullable": true, 700 | "type": "boolean", 701 | "example": true 702 | }, 703 | "level": { 704 | "nullable": false, 705 | "type": "number", 706 | "example": 56 707 | } 708 | } 709 | } 710 | } 711 | } 712 | } 713 | } 714 | } 715 | } 716 | }, 717 | "202": { 718 | "$ref": "#/components/responses/202" 719 | }, 720 | "400": { 721 | "$ref": "#/components/responses/400" 722 | }, 723 | "404": { 724 | "$ref": "#/components/responses/404" 725 | }, 726 | "429": { 727 | "$ref": "#/components/responses/429" 728 | }, 729 | "500": { 730 | "$ref": "#/components/responses/500" 731 | }, 732 | "503": { 733 | "$ref": "#/components/responses/503" 734 | } 735 | } 736 | } 737 | }, 738 | "/v1/guild": { 739 | "get": { 740 | "summary": "Retrieve guild profile.", 741 | "description": "Retrieve the profile of a guild by its name.", 742 | "operationId": "getGuild", 743 | "parameters": [ 744 | { 745 | "name": "guildName", 746 | "in": "query", 747 | "description": "Guild's name. It should be at least 2 characters long and can only contain A-Z, a-z, 0-9, _ characters.", 748 | "required": true, 749 | "schema": { 750 | "type": "string" 751 | } 752 | }, 753 | { 754 | "$ref": "#/components/parameters/region" 755 | } 756 | ], 757 | "responses": { 758 | "200": { 759 | "description": "OK.", 760 | "headers": { 761 | "Date": { 762 | "description": "Date and time of when the request was processed.", 763 | "schema": { 764 | "type": "string", 765 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 766 | } 767 | }, 768 | "Expires": { 769 | "description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.", 770 | "schema": { 771 | "type": "string", 772 | "example": "Thu, 01 Jan 1970 03:00:00 GMT" 773 | } 774 | }, 775 | "Last-Modified": { 776 | "description": "Date and time when the scraper fetched the data.", 777 | "schema": { 778 | "type": "string", 779 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 780 | } 781 | }, 782 | "X-Ratelimit-Limit": { 783 | "description": "Maximum number of requests per minute per IP address.", 784 | "schema": { 785 | "type": "integer", 786 | "example": 512 787 | } 788 | }, 789 | "X-Ratelimit-Remaining": { 790 | "description": "Number of requests left for your IP address for the current minute.", 791 | "schema": { 792 | "type": "integer", 793 | "example": 256 794 | } 795 | }, 796 | "X-Ratelimit-Reset": { 797 | "description": "Timestamp of the next minute, when rate limit resets.", 798 | "schema": { 799 | "type": "integer", 800 | "example": 1746433664 801 | } 802 | } 803 | }, 804 | "content": { 805 | "application/json": { 806 | "schema": { 807 | "title": "Guild", 808 | "type": "object", 809 | "properties": { 810 | "name": { 811 | "type": "string", 812 | "example": "TumblrGirls" 813 | }, 814 | "region": { 815 | "type": "string", 816 | "enum": [ 817 | "EU", 818 | "KR", 819 | "NA", 820 | "SA" 821 | ] 822 | }, 823 | "createdOn": { 824 | "type": "string", 825 | "example": "2020-02-23T00:00:00Z" 826 | }, 827 | "master": { 828 | "type": "object", 829 | "properties": { 830 | "familyName": { 831 | "type": "string", 832 | "example": "Apple" 833 | }, 834 | "profileTarget": { 835 | "type": "string", 836 | "example": "XXX" 837 | } 838 | } 839 | }, 840 | "members": { 841 | "type": "array", 842 | "items": { 843 | "type": "object", 844 | "properties": { 845 | "familyName": { 846 | "type": "string", 847 | "example": "Apple" 848 | }, 849 | "profileTarget": { 850 | "type": "string", 851 | "example": "XXX" 852 | } 853 | } 854 | } 855 | }, 856 | "population": { 857 | "type": "number", 858 | "example": 1 859 | }, 860 | "occupying": { 861 | "type": "string", 862 | "example": "Mediah Territory" 863 | } 864 | } 865 | } 866 | } 867 | } 868 | }, 869 | "202": { 870 | "$ref": "#/components/responses/202" 871 | }, 872 | "400": { 873 | "$ref": "#/components/responses/400" 874 | }, 875 | "404": { 876 | "$ref": "#/components/responses/404" 877 | }, 878 | "429": { 879 | "$ref": "#/components/responses/429" 880 | }, 881 | "500": { 882 | "$ref": "#/components/responses/500" 883 | }, 884 | "503": { 885 | "$ref": "#/components/responses/503" 886 | } 887 | } 888 | } 889 | }, 890 | "/v1/guild/search": { 891 | "get": { 892 | "summary": "Search for a guild.", 893 | "description": "Search for a guild by combination of its region and name.", 894 | "operationId": "getGuildSearch", 895 | "parameters": [ 896 | { 897 | "name": "query", 898 | "in": "query", 899 | "description": "The query string should be at least 2 characters long and can only contain A-Z, a-z, 0-9, _ characters.", 900 | "required": true, 901 | "schema": { 902 | "type": "string" 903 | } 904 | }, 905 | { 906 | "$ref": "#/components/parameters/region" 907 | } 908 | ], 909 | "responses": { 910 | "200": { 911 | "description": "OK.", 912 | "headers": { 913 | "Date": { 914 | "description": "Date and time of when the request was processed.", 915 | "schema": { 916 | "type": "string", 917 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 918 | } 919 | }, 920 | "Expires": { 921 | "description": "Date and time of when cache for this response will expire, and the scraper will be ready to refetch the data with the next request.", 922 | "schema": { 923 | "type": "string", 924 | "example": "Thu, 01 Jan 1970 03:00:00 GMT" 925 | } 926 | }, 927 | "Last-Modified": { 928 | "description": "Date and time when the scraper fetched the data.", 929 | "schema": { 930 | "type": "string", 931 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 932 | } 933 | }, 934 | "X-Ratelimit-Limit": { 935 | "description": "Maximum number of requests per minute per IP address.", 936 | "schema": { 937 | "type": "integer", 938 | "example": 512 939 | } 940 | }, 941 | "X-Ratelimit-Remaining": { 942 | "description": "Number of requests left for your IP address for the current minute.", 943 | "schema": { 944 | "type": "integer", 945 | "example": 256 946 | } 947 | }, 948 | "X-Ratelimit-Reset": { 949 | "description": "Timestamp of the next minute, when rate limit resets.", 950 | "schema": { 951 | "type": "integer", 952 | "example": 1746433664 953 | } 954 | } 955 | }, 956 | "content": { 957 | "application/json": { 958 | "schema": { 959 | "title": "GuildSearchResult", 960 | "type": "array", 961 | "items": { 962 | "type": "object", 963 | "properties": { 964 | "name": { 965 | "type": "string", 966 | "example": "TumblrGirls" 967 | }, 968 | "region": { 969 | "type": "string", 970 | "enum": [ 971 | "EU", 972 | "KR", 973 | "NA", 974 | "SA" 975 | ] 976 | }, 977 | "createdOn": { 978 | "type": "string", 979 | "example": "2020-02-23T00:00:00Z" 980 | }, 981 | "master": { 982 | "type": "object", 983 | "properties": { 984 | "familyName": { 985 | "type": "string", 986 | "example": "Apple" 987 | }, 988 | "profileTarget": { 989 | "type": "string", 990 | "example": "XXX" 991 | } 992 | } 993 | }, 994 | "population": { 995 | "type": "number", 996 | "example": 1 997 | } 998 | } 999 | } 1000 | } 1001 | } 1002 | } 1003 | }, 1004 | "202": { 1005 | "$ref": "#/components/responses/202" 1006 | }, 1007 | "400": { 1008 | "$ref": "#/components/responses/400" 1009 | }, 1010 | "404": { 1011 | "$ref": "#/components/responses/404" 1012 | }, 1013 | "429": { 1014 | "$ref": "#/components/responses/429" 1015 | }, 1016 | "500": { 1017 | "$ref": "#/components/responses/500" 1018 | }, 1019 | "503": { 1020 | "$ref": "#/components/responses/503" 1021 | } 1022 | } 1023 | } 1024 | }, 1025 | "/v1/cache": { 1026 | "get": { 1027 | "summary": "Retrieve cached routes", 1028 | "operationId": "getCache", 1029 | "responses": { 1030 | "200": { 1031 | "description": "OK.", 1032 | "headers": { 1033 | "Date": { 1034 | "description": "Date and time of when the request was processed.", 1035 | "schema": { 1036 | "type": "string", 1037 | "example": "Thu, 01 Jan 1970 00:00:00 GMT" 1038 | } 1039 | }, 1040 | "X-Ratelimit-Limit": { 1041 | "description": "Maximum number of requests per minute per IP address.", 1042 | "schema": { 1043 | "type": "integer", 1044 | "example": 512 1045 | } 1046 | }, 1047 | "X-Ratelimit-Remaining": { 1048 | "description": "Number of requests left for your IP address for the current minute.", 1049 | "schema": { 1050 | "type": "integer", 1051 | "example": 256 1052 | } 1053 | }, 1054 | "X-Ratelimit-Reset": { 1055 | "description": "Timestamp of the next minute, when rate limit resets.", 1056 | "schema": { 1057 | "type": "integer", 1058 | "example": 1746433664 1059 | } 1060 | } 1061 | }, 1062 | "content": { 1063 | "application/json": { 1064 | "schema": { 1065 | "type": "object", 1066 | "properties": { 1067 | "/adventurer": { 1068 | "type": "array", 1069 | "items": { 1070 | "type": "object", 1071 | "properties": { 1072 | "profileTarget": { 1073 | "nullable": false, 1074 | "type": "string", 1075 | "example": "XXX" 1076 | }, 1077 | "region": { 1078 | "nullable": false, 1079 | "type": "string", 1080 | "enum": [ 1081 | "EU", 1082 | "KR", 1083 | "NA", 1084 | "SA" 1085 | ] 1086 | } 1087 | } 1088 | } 1089 | }, 1090 | "/adventurer/search": { 1091 | "type": "array", 1092 | "items": { 1093 | "type": "object", 1094 | "properties": { 1095 | "query": { 1096 | "nullable": false, 1097 | "type": "string", 1098 | "example": "Apple" 1099 | }, 1100 | "region": { 1101 | "nullable": false, 1102 | "type": "string", 1103 | "enum": [ 1104 | "EU", 1105 | "KR", 1106 | "NA", 1107 | "SA" 1108 | ] 1109 | }, 1110 | "searchType": { 1111 | "nullable": false, 1112 | "type": "string", 1113 | "enum": [ 1114 | "familyName", 1115 | "characterName" 1116 | ] 1117 | } 1118 | } 1119 | } 1120 | }, 1121 | "/guild": { 1122 | "type": "array", 1123 | "items": { 1124 | "type": "object", 1125 | "properties": { 1126 | "guildName": { 1127 | "nullable": false, 1128 | "type": "string", 1129 | "example": "TumblrGirls" 1130 | }, 1131 | "region": { 1132 | "nullable": false, 1133 | "type": "string", 1134 | "enum": [ 1135 | "EU", 1136 | "KR", 1137 | "NA", 1138 | "SA" 1139 | ] 1140 | } 1141 | } 1142 | } 1143 | }, 1144 | "/guild/search": { 1145 | "type": "array", 1146 | "items": { 1147 | "type": "object", 1148 | "properties": { 1149 | "query": { 1150 | "nullable": false, 1151 | "type": "string", 1152 | "example": "TumblrGirls" 1153 | }, 1154 | "region": { 1155 | "nullable": false, 1156 | "type": "string", 1157 | "enum": [ 1158 | "EU", 1159 | "KR", 1160 | "NA", 1161 | "SA" 1162 | ] 1163 | } 1164 | } 1165 | } 1166 | } 1167 | } 1168 | } 1169 | } 1170 | } 1171 | } 1172 | } 1173 | } 1174 | } 1175 | } 1176 | } 1177 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module bdo-rest-api 2 | 3 | go 1.24.0 4 | 5 | require ( 6 | github.com/gocolly/colly/v2 v2.1.1-0.20240605174350-99b7fb1b87d1 7 | github.com/patrickmn/go-cache v2.1.0+incompatible 8 | github.com/sa-/slicefunk v0.1.4 9 | github.com/spf13/viper v1.20.1 10 | github.com/ulule/limiter/v3 v3.11.2 11 | go.mongodb.org/mongo-driver/v2 v2.1.0 12 | golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa 13 | ) 14 | 15 | require ( 16 | github.com/PuerkitoBio/goquery v1.10.2 // indirect 17 | github.com/andybalholm/cascadia v1.3.3 // indirect 18 | github.com/antchfx/htmlquery v1.3.4 // indirect 19 | github.com/antchfx/xmlquery v1.4.4 // indirect 20 | github.com/antchfx/xpath v1.3.3 // indirect 21 | github.com/bits-and-blooms/bitset v1.21.0 // indirect 22 | github.com/fsnotify/fsnotify v1.8.0 // indirect 23 | github.com/go-viper/mapstructure/v2 v2.2.1 // indirect 24 | github.com/gobwas/glob v0.2.3 // indirect 25 | github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect 26 | github.com/golang/protobuf v1.5.4 // indirect 27 | github.com/golang/snappy v0.0.4 // indirect 28 | github.com/kennygrant/sanitize v1.2.4 // indirect 29 | github.com/klauspost/compress v1.18.0 // indirect 30 | github.com/nlnwa/whatwg-url v0.5.1 // indirect 31 | github.com/pelletier/go-toml/v2 v2.2.3 // indirect 32 | github.com/pkg/errors v0.9.1 // indirect 33 | github.com/sagikazarmark/locafero v0.7.0 // indirect 34 | github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d // indirect 35 | github.com/sourcegraph/conc v0.3.0 // indirect 36 | github.com/spf13/afero v1.12.0 // indirect 37 | github.com/spf13/cast v1.7.1 // indirect 38 | github.com/spf13/pflag v1.0.6 // indirect 39 | github.com/subosito/gotenv v1.6.0 // indirect 40 | github.com/temoto/robotstxt v1.1.2 // indirect 41 | github.com/vardius/message-bus v1.1.5 42 | github.com/xdg-go/pbkdf2 v1.0.0 // indirect 43 | github.com/xdg-go/scram v1.1.2 // indirect 44 | github.com/xdg-go/stringprep v1.0.4 // indirect 45 | github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect 46 | go.uber.org/atomic v1.9.0 // indirect 47 | go.uber.org/multierr v1.9.0 // indirect 48 | golang.org/x/crypto v0.35.0 // indirect 49 | golang.org/x/net v0.35.0 // indirect 50 | golang.org/x/sync v0.11.0 // indirect 51 | golang.org/x/sys v0.30.0 // indirect 52 | golang.org/x/text v0.22.0 // indirect 53 | google.golang.org/appengine v1.6.8 // indirect 54 | google.golang.org/protobuf v1.36.5 // indirect 55 | gopkg.in/yaml.v3 v3.0.1 // indirect 56 | ) 57 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= 2 | github.com/PuerkitoBio/goquery v1.10.2 h1:7fh2BdHcG6VFZsK7toXBT/Bh1z5Wmy8Q9MV9HqT2AM8= 3 | github.com/PuerkitoBio/goquery v1.10.2/go.mod h1:0guWGjcLu9AYC7C1GHnpysHy056u9aEkUHwhdnePMCU= 4 | github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= 5 | github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= 6 | github.com/andybalholm/cascadia v1.3.3 h1:AG2YHrzJIm4BZ19iwJ/DAua6Btl3IwJX+VI4kktS1LM= 7 | github.com/andybalholm/cascadia v1.3.3/go.mod h1:xNd9bqTn98Ln4DwST8/nG+H0yuB8Hmgu1YHNnWw0GeA= 8 | github.com/antchfx/htmlquery v1.2.3/go.mod h1:B0ABL+F5irhhMWg54ymEZinzMSi0Kt3I2if0BLYa3V0= 9 | github.com/antchfx/htmlquery v1.3.4 h1:Isd0srPkni2iNTWCwVj/72t7uCphFeor5Q8nCzj1jdQ= 10 | github.com/antchfx/htmlquery v1.3.4/go.mod h1:K9os0BwIEmLAvTqaNSua8tXLWRWZpocZIH73OzWQbwM= 11 | github.com/antchfx/xmlquery v1.3.4/go.mod h1:64w0Xesg2sTaawIdNqMB+7qaW/bSqkQm+ssPaCMWNnc= 12 | github.com/antchfx/xmlquery v1.4.4 h1:mxMEkdYP3pjKSftxss4nUHfjBhnMk4imGoR96FRY2dg= 13 | github.com/antchfx/xmlquery v1.4.4/go.mod h1:AEPEEPYE9GnA2mj5Ur2L5Q5/2PycJ0N9Fusrx9b12fc= 14 | github.com/antchfx/xpath v1.1.6/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= 15 | github.com/antchfx/xpath v1.1.10/go.mod h1:Yee4kTMuNiPYJ7nSNorELQMr1J33uOpXDMByNYhvtNk= 16 | github.com/antchfx/xpath v1.3.3 h1:tmuPQa1Uye0Ym1Zn65vxPgfltWb/Lxu2jeqIGteJSRs= 17 | github.com/antchfx/xpath v1.3.3/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs= 18 | github.com/bits-and-blooms/bitset v1.2.2-0.20220111210104-dfa3e347c392/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= 19 | github.com/bits-and-blooms/bitset v1.20.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= 20 | github.com/bits-and-blooms/bitset v1.21.0 h1:9RlxRbMI5dRNNburKqfDSiz5POfImKgtablyV01WUw0= 21 | github.com/bits-and-blooms/bitset v1.21.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= 22 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 23 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 24 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 25 | github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= 26 | github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= 27 | github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M= 28 | github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0= 29 | github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= 30 | github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= 31 | github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y= 32 | github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8= 33 | github.com/gocolly/colly/v2 v2.1.1-0.20240605174350-99b7fb1b87d1 h1:NIM5Ryhb9ojIT4KYOSSvOkTSr0xnqe7rf/xp77h3gsA= 34 | github.com/gocolly/colly/v2 v2.1.1-0.20240605174350-99b7fb1b87d1/go.mod h1:PP9l5hevtSfmOBhVEbJOYv7rHXvC7zLYg5MeAhP/+Bo= 35 | github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 36 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= 37 | github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= 38 | github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= 39 | github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= 40 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 41 | github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 42 | github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= 43 | github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= 44 | github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= 45 | github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= 46 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 47 | github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= 48 | github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= 49 | github.com/jawher/mow.cli v1.1.0/go.mod h1:aNaQlc7ozF3vw6IJ2dHjp2ZFiA4ozMIYY6PyuRJwlUg= 50 | github.com/kennygrant/sanitize v1.2.4 h1:gN25/otpP5vAsO2djbMhF/LQX6R7+O1TB4yv8NzpJ3o= 51 | github.com/kennygrant/sanitize v1.2.4/go.mod h1:LGsjYYtgxbetdg5owWB2mpgUL6e2nfw2eObZ0u0qvak= 52 | github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= 53 | github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= 54 | github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= 55 | github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= 56 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 57 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 58 | github.com/nlnwa/whatwg-url v0.1.2/go.mod h1:b0r+dEyM/KztLMDSVY6ApcO9Fmzgq+e9+Ugq20UBYck= 59 | github.com/nlnwa/whatwg-url v0.5.1 h1:UTE/wOlqhUuFlNv5TiQbD13amU8uRwonc2S6EsQYUfk= 60 | github.com/nlnwa/whatwg-url v0.5.1/go.mod h1:x0FPXJzzOEieQtsBT/AKvbiBbQ46YlL6Xa7m02M1ECk= 61 | github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= 62 | github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= 63 | github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= 64 | github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= 65 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= 66 | github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 67 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 68 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 69 | github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= 70 | github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= 71 | github.com/sa-/slicefunk v0.1.4 h1:fCgDllo0nYVywdREyJm53BQ5rfMW8pin57yNVpyPxNU= 72 | github.com/sa-/slicefunk v0.1.4/go.mod h1:k0abNpV9EW8LIPl2+Hc9RiKsojKmsUhNNGFyMpjMTCI= 73 | github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo= 74 | github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k= 75 | github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= 76 | github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d h1:hrujxIzL1woJ7AwssoOcM/tq5JjjG2yYOc8odClEiXA= 77 | github.com/saintfish/chardet v0.0.0-20230101081208-5e3ef4b5456d/go.mod h1:uugorj2VCxiV1x+LzaIdVa9b4S4qGAcH6cbhh4qVxOU= 78 | github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo= 79 | github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= 80 | github.com/spf13/afero v1.12.0 h1:UcOPyRBYczmFn6yvphxkn9ZEOY65cpwGKb5mL36mrqs= 81 | github.com/spf13/afero v1.12.0/go.mod h1:ZTlWwG4/ahT8W7T0WQ5uYmjI9duaLQGy3Q2OAl4sk/4= 82 | github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y= 83 | github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= 84 | github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= 85 | github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= 86 | github.com/spf13/viper v1.20.1 h1:ZMi+z/lvLyPSCoNtFCpqjy0S4kPbirhpTMwl8BkW9X4= 87 | github.com/spf13/viper v1.20.1/go.mod h1:P9Mdzt1zoHIG8m2eZQinpiBjo6kCmZSKBClNNqjJvu4= 88 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 89 | github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= 90 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 91 | github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= 92 | github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= 93 | github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= 94 | github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= 95 | github.com/temoto/robotstxt v1.1.1/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= 96 | github.com/temoto/robotstxt v1.1.2 h1:W2pOjSJ6SWvldyEuiFXNxz3xZ8aiWX5LbfDiOFd7Fxg= 97 | github.com/temoto/robotstxt v1.1.2/go.mod h1:+1AmkuG3IYkh1kv0d2qEB9Le88ehNO0zwOr3ujewlOo= 98 | github.com/ulule/limiter/v3 v3.11.2 h1:P4yOrxoEMJbOTfRJR2OzjL90oflzYPPmWg+dvwN2tHA= 99 | github.com/ulule/limiter/v3 v3.11.2/go.mod h1:QG5GnFOCV+k7lrL5Y8kgEeeflPH3+Cviqlqa8SVSQxI= 100 | github.com/vardius/message-bus v1.1.5 h1:YSAC2WB4HRlwc4neFPTmT88kzzoiQ+9WRRbej/E/LZc= 101 | github.com/vardius/message-bus v1.1.5/go.mod h1:6xladCV2lMkUAE4bzzS85qKOiB5miV7aBVRafiTJGqw= 102 | github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= 103 | github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= 104 | github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= 105 | github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= 106 | github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= 107 | github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= 108 | github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= 109 | github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= 110 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 111 | go.mongodb.org/mongo-driver/v2 v2.1.0 h1:/ELnVNjmfUKDsoBisXxuJL0noR9CfeUIrP7Yt3R+egg= 112 | go.mongodb.org/mongo-driver/v2 v2.1.0/go.mod h1:AWiLRShSrk5RHQS3AEn3RL19rqOzVq49MCpWQ3x/huI= 113 | go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE= 114 | go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= 115 | go.uber.org/multierr v1.9.0 h1:7fIwc/ZtS0q++VgcfqFDxSBZVv/Xo49/SYnDFupUwlI= 116 | go.uber.org/multierr v1.9.0/go.mod h1:X2jQV1h+kxSjClGpnseKVIxpmcjrj7MNnI0bnlfKTVQ= 117 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 118 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= 119 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 120 | golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= 121 | golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= 122 | golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU= 123 | golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= 124 | golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= 125 | golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= 126 | golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs= 127 | golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ= 128 | golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrCPyJZ+eyRsABUPs1mz4= 129 | golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk= 130 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 131 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 132 | golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 133 | golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 134 | golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= 135 | golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= 136 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 137 | golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= 138 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 139 | golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 140 | golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= 141 | golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= 142 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 143 | golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 144 | golang.org/x/net v0.0.0-20220114011407-0dd24b26b47d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= 145 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 146 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 147 | golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= 148 | golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= 149 | golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= 150 | golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= 151 | golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= 152 | golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= 153 | golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k= 154 | golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8= 155 | golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk= 156 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 157 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 158 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 159 | golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= 160 | golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 161 | golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 162 | golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 163 | golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= 164 | golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= 165 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 166 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 167 | golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 168 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 169 | golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 170 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 171 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 172 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 173 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 174 | golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 175 | golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 176 | golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 177 | golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 178 | golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 179 | golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 180 | golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 181 | golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= 182 | golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= 183 | golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE= 184 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 185 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 186 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 187 | golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= 188 | golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU= 189 | golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= 190 | golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= 191 | golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= 192 | golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM= 193 | golang.org/x/term v0.28.0/go.mod h1:Sw/lC2IAUZ92udQNf3WodGtn4k/XoLyZoh8v/8uiwek= 194 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 195 | golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= 196 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 197 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 198 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 199 | golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= 200 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 201 | golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 202 | golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 203 | golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 204 | golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= 205 | golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= 206 | golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= 207 | golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY= 208 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 209 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 210 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 211 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 212 | golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58= 213 | golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= 214 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 215 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 216 | google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= 217 | google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= 218 | google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= 219 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 220 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 221 | google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= 222 | google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= 223 | google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= 224 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 225 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= 226 | gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 227 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 228 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 229 | -------------------------------------------------------------------------------- /handlers/ListenAndServe.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "time" 7 | 8 | "bdo-rest-api/logger" 9 | "bdo-rest-api/middleware" 10 | 11 | "github.com/spf13/viper" 12 | ) 13 | 14 | func ListenAndServe() { 15 | mux := http.NewServeMux() 16 | 17 | mux.HandleFunc("GET /v1", getStatus) 18 | mux.HandleFunc("GET /v1/adventurer", getAdventurer) 19 | mux.HandleFunc("GET /v1/adventurer/search", getAdventurerSearch) 20 | mux.HandleFunc("GET /v1/cache", getCache) 21 | mux.HandleFunc("GET /v1/guild", getGuild) 22 | mux.HandleFunc("GET /v1/guild/search", getGuildSearch) 23 | mux.HandleFunc("/", catchall) 24 | 25 | middlewareStack := middleware.CreateStack( 26 | middleware.GetSetHeadersMiddleware(), 27 | middleware.GetRateLimitMiddleware(), 28 | ) 29 | 30 | srv := &http.Server{ 31 | Addr: fmt.Sprintf("0.0.0.0:%v", viper.GetInt("port")), 32 | Handler: middlewareStack(mux), 33 | IdleTimeout: 30 * time.Second, 34 | ReadTimeout: 10 * time.Second, 35 | WriteTimeout: 10 * time.Second, 36 | } 37 | 38 | logger.Error(srv.ListenAndServe().Error()) 39 | } 40 | -------------------------------------------------------------------------------- /handlers/catchall.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | ) 6 | 7 | func catchall(w http.ResponseWriter, r *http.Request) { 8 | giveBadRequestResponse(w, "Requested route is invalid. See documentation "+docsLink) 9 | } 10 | -------------------------------------------------------------------------------- /handlers/getAdventurer.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | 7 | "bdo-rest-api/cache" 8 | "bdo-rest-api/scraper" 9 | "bdo-rest-api/validators" 10 | ) 11 | 12 | func getAdventurer(w http.ResponseWriter, r *http.Request) { 13 | profileTarget, profileTargetOk, profileTargetValidationMessage := validators.ValidateProfileTargetQueryParam(r.URL.Query()["profileTarget"]) 14 | if !profileTargetOk { 15 | giveBadRequestResponse(w, profileTargetValidationMessage) 16 | return 17 | } 18 | 19 | region, regionOk, regionValidationMessage := validators.ValidateRegionQueryParam(r.URL.Query()["region"]) 20 | if !regionOk { 21 | giveBadRequestResponse(w, regionValidationMessage) 22 | return 23 | } 24 | 25 | if data, status, date, expires, ok := cache.Profiles.GetRecord([]string{region, profileTarget}); ok { 26 | w.Header().Set("Expires", expires) 27 | w.Header().Set("Last-Modified", date) 28 | 29 | if status == http.StatusOK { 30 | json.NewEncoder(w).Encode(data) 31 | } else { 32 | w.WriteHeader(status) 33 | } 34 | 35 | return 36 | } 37 | 38 | if ok := giveMaintenanceResponse(w, region); ok { 39 | return 40 | } 41 | 42 | if tasksQuantityExceeded := scraper.EnqueueAdventurer(r.Header.Get("CF-Connecting-IP"), region, profileTarget); tasksQuantityExceeded { 43 | w.WriteHeader(http.StatusTooManyRequests) 44 | json.NewEncoder(w).Encode(map[string]string{ 45 | "message": "You have exceeded the maximum number of concurrent tasks.", 46 | }) 47 | 48 | return 49 | } 50 | 51 | w.WriteHeader(http.StatusAccepted) 52 | json.NewEncoder(w).Encode(map[string]string{ 53 | "message": "Player profile is being fetched. Please try again later.", 54 | }) 55 | } 56 | -------------------------------------------------------------------------------- /handlers/getAdventurerSearch.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | 7 | "bdo-rest-api/cache" 8 | "bdo-rest-api/scraper" 9 | "bdo-rest-api/validators" 10 | ) 11 | 12 | func getAdventurerSearch(w http.ResponseWriter, r *http.Request) { 13 | region, regionOk, regionValidationMessage := validators.ValidateRegionQueryParam(r.URL.Query()["region"]) 14 | if !regionOk { 15 | giveBadRequestResponse(w, regionValidationMessage) 16 | return 17 | } 18 | 19 | searchTypeQueryParam := r.URL.Query()["searchType"] 20 | searchType := validators.ValidateSearchTypeQueryParam(searchTypeQueryParam) 21 | 22 | query, queryOk, queryValidationMessage := validators.ValidateAdventurerNameQueryParam(r.URL.Query()["query"], region, searchType) 23 | if !queryOk { 24 | giveBadRequestResponse(w, queryValidationMessage) 25 | return 26 | } 27 | 28 | if data, status, date, expires, ok := cache.ProfileSearch.GetRecord([]string{region, query, searchType}); ok { 29 | w.Header().Set("Expires", expires) 30 | w.Header().Set("Last-Modified", date) 31 | 32 | if status == http.StatusOK { 33 | json.NewEncoder(w).Encode(data) 34 | } else { 35 | w.WriteHeader(status) 36 | } 37 | 38 | return 39 | } 40 | 41 | if ok := giveMaintenanceResponse(w, region); ok { 42 | return 43 | } 44 | 45 | if tasksQuantityExceeded := scraper.EnqueueAdventurerSearch(r.Header.Get("CF-Connecting-IP"), region, query, searchType); tasksQuantityExceeded { 46 | w.WriteHeader(http.StatusTooManyRequests) 47 | json.NewEncoder(w).Encode(map[string]string{ 48 | "message": "You have exceeded the maximum number of concurrent tasks.", 49 | }) 50 | 51 | return 52 | } 53 | 54 | w.WriteHeader(http.StatusAccepted) 55 | json.NewEncoder(w).Encode(map[string]string{ 56 | "message": "Player search is being fetched. Please try again later.", 57 | }) 58 | } 59 | -------------------------------------------------------------------------------- /handlers/getCache.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "bdo-rest-api/cache" 5 | "encoding/json" 6 | "net/http" 7 | "strings" 8 | 9 | sf "github.com/sa-/slicefunk" 10 | ) 11 | 12 | func getParseCacheKey(cacheType string) func(string) map[string]interface{} { 13 | return func(key string) map[string]interface{} { 14 | parts := strings.Split(key, ",") 15 | 16 | switch cacheType { 17 | case "/adventurer": 18 | return map[string]interface{}{ 19 | "region": parts[0], 20 | "profileTarget": parts[1], 21 | } 22 | case "/adventurer/search": 23 | 24 | return map[string]interface{}{ 25 | "region": parts[0], 26 | "query": parts[1], 27 | "searhType": parts[2], 28 | } 29 | case "/guild": 30 | return map[string]interface{}{ 31 | "region": parts[0], 32 | "guildName": parts[1], 33 | } 34 | case "/guild/search": 35 | return map[string]interface{}{ 36 | "region": parts[0], 37 | "query": parts[1], 38 | } 39 | default: 40 | return nil 41 | } 42 | } 43 | } 44 | 45 | func getCache(w http.ResponseWriter, r *http.Request) { 46 | json.NewEncoder(w).Encode(map[string]interface{}{ 47 | "/adventurer": sf.Map(cache.Profiles.GetKeys(), getParseCacheKey("/adventurer")), 48 | "/adventurer/search": sf.Map(cache.ProfileSearch.GetKeys(), getParseCacheKey("/adventurer/search")), 49 | "/guild": sf.Map(cache.GuildProfiles.GetKeys(), getParseCacheKey("/guild")), 50 | "/guild/search": sf.Map(cache.GuildSearch.GetKeys(), getParseCacheKey("/guild/search")), 51 | }) 52 | } 53 | -------------------------------------------------------------------------------- /handlers/getGuild.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | 7 | "bdo-rest-api/cache" 8 | "bdo-rest-api/scraper" 9 | "bdo-rest-api/validators" 10 | ) 11 | 12 | func getGuild(w http.ResponseWriter, r *http.Request) { 13 | name, nameOk, nameValidationMessage := validators.ValidateGuildNameQueryParam(r.URL.Query()["guildName"]) 14 | if !nameOk { 15 | giveBadRequestResponse(w, nameValidationMessage) 16 | return 17 | } 18 | 19 | region, regionOk, regionValidationMessage := validators.ValidateRegionQueryParam(r.URL.Query()["region"]) 20 | if !regionOk { 21 | giveBadRequestResponse(w, regionValidationMessage) 22 | return 23 | } 24 | 25 | if data, status, date, expires, ok := cache.GuildProfiles.GetRecord([]string{region, name}); ok { 26 | w.Header().Set("Expires", expires) 27 | w.Header().Set("Last-Modified", date) 28 | 29 | if status == http.StatusOK { 30 | json.NewEncoder(w).Encode(data) 31 | } else { 32 | w.WriteHeader(status) 33 | } 34 | 35 | return 36 | } 37 | 38 | if ok := giveMaintenanceResponse(w, region); ok { 39 | return 40 | } 41 | 42 | if tasksQuantityExceeded := scraper.EnqueueGuild(r.Header.Get("CF-Connecting-IP"), region, name); tasksQuantityExceeded { 43 | w.WriteHeader(http.StatusTooManyRequests) 44 | json.NewEncoder(w).Encode(map[string]string{ 45 | "message": "You have exceeded the maximum number of concurrent tasks.", 46 | }) 47 | 48 | return 49 | } 50 | 51 | w.WriteHeader(http.StatusAccepted) 52 | json.NewEncoder(w).Encode(map[string]string{ 53 | "message": "Guild profile is being fetched. Please try again later.", 54 | }) 55 | } 56 | -------------------------------------------------------------------------------- /handlers/getGuildSearch.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | 7 | "bdo-rest-api/cache" 8 | "bdo-rest-api/scraper" 9 | "bdo-rest-api/validators" 10 | ) 11 | 12 | func getGuildSearch(w http.ResponseWriter, r *http.Request) { 13 | name, nameOk, nameValidationMessage := validators.ValidateGuildNameQueryParam(r.URL.Query()["query"]) 14 | if !nameOk { 15 | giveBadRequestResponse(w, nameValidationMessage) 16 | return 17 | } 18 | 19 | region, regionOk, regionValidationMessage := validators.ValidateRegionQueryParam(r.URL.Query()["region"]) 20 | if !regionOk { 21 | giveBadRequestResponse(w, regionValidationMessage) 22 | return 23 | } 24 | 25 | if data, status, date, expires, ok := cache.GuildSearch.GetRecord([]string{region, name}); ok { 26 | w.Header().Set("Expires", expires) 27 | w.Header().Set("Last-Modified", date) 28 | 29 | if status == http.StatusOK { 30 | json.NewEncoder(w).Encode(data) 31 | } else { 32 | w.WriteHeader(status) 33 | } 34 | 35 | return 36 | } 37 | 38 | if ok := giveMaintenanceResponse(w, region); ok { 39 | return 40 | } 41 | 42 | if tasksQuantityExceeded := scraper.EnqueueGuildSearch(r.Header.Get("CF-Connecting-IP"), region, name); tasksQuantityExceeded { 43 | w.WriteHeader(http.StatusTooManyRequests) 44 | json.NewEncoder(w).Encode(map[string]string{ 45 | "message": "You have exceeded the maximum number of concurrent tasks.", 46 | }) 47 | 48 | return 49 | } 50 | 51 | w.WriteHeader(http.StatusAccepted) 52 | json.NewEncoder(w).Encode(map[string]string{ 53 | "message": "Guild search is being fetched. Please try again later.", 54 | }) 55 | } 56 | -------------------------------------------------------------------------------- /handlers/getStatus.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | "time" 7 | 8 | "bdo-rest-api/cache" 9 | "bdo-rest-api/scraper" 10 | 11 | "github.com/spf13/viper" 12 | ) 13 | 14 | var initTime = time.Now() 15 | var version = "1.11.3" 16 | 17 | func getStatus(w http.ResponseWriter, r *http.Request) { 18 | json.NewEncoder(w).Encode(map[string]interface{}{ 19 | "cache": map[string]interface{}{ 20 | "lastDetectedMaintenance": scraper.GetLastCloseTimes(), 21 | "responses": map[string]int{ 22 | "/adventurer": cache.Profiles.GetItemCount(), 23 | "/adventurer/search": cache.ProfileSearch.GetItemCount(), 24 | "/guild": cache.GuildProfiles.GetItemCount(), 25 | "/guild/search": cache.GuildSearch.GetItemCount(), 26 | }, 27 | "ttl": map[string]string{ 28 | "general": viper.GetDuration("cachettl").Round(time.Minute).String(), 29 | "maintenanceStatus": viper.GetDuration("maintenancettl").Round(time.Minute).String(), 30 | }, 31 | }, 32 | "docs": docsLink, 33 | "proxies": len(viper.GetStringSlice("proxy")), 34 | "rateLimit": viper.GetInt64("ratelimit"), 35 | "taskQueue": map[string]int{ 36 | "maxTasksPerClient": viper.GetInt("maxtasksperclient"), 37 | "taskRetries": viper.GetInt("taskretries"), 38 | }, 39 | "uptime": time.Since(initTime).Round(time.Second).String(), 40 | "version": version, 41 | }) 42 | } 43 | -------------------------------------------------------------------------------- /handlers/giveBadRequestResponse.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "encoding/json" 5 | "net/http" 6 | ) 7 | 8 | const docsLink = "https://man90es.github.io/BDO-REST-API" 9 | 10 | func giveBadRequestResponse(w http.ResponseWriter, message string) { 11 | w.WriteHeader(http.StatusBadRequest) 12 | 13 | json.NewEncoder(w).Encode(map[string]string{ 14 | "message": message, 15 | }) 16 | } 17 | -------------------------------------------------------------------------------- /handlers/giveMaintenanceResponse.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | 6 | "bdo-rest-api/scraper" 7 | "bdo-rest-api/utils" 8 | ) 9 | 10 | func giveMaintenanceResponse(w http.ResponseWriter, region string) (ok bool) { 11 | isCloseTime, expires := scraper.GetCloseTime(region) 12 | 13 | if !isCloseTime { 14 | return false 15 | } 16 | 17 | w.Header().Set("Expires", utils.FormatDateForHeaders(expires)) 18 | w.WriteHeader(http.StatusServiceUnavailable) 19 | return true 20 | } 21 | -------------------------------------------------------------------------------- /logger/Log.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import "time" 4 | 5 | type Log struct { 6 | CreatedAt time.Time `json:"createdAt" bson:"createdAt"` 7 | Level string `json:"level" bson:"level"` 8 | Message string `json:"message" bson:"message"` 9 | } 10 | -------------------------------------------------------------------------------- /logger/logger.go: -------------------------------------------------------------------------------- 1 | package logger 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "log" 7 | "os" 8 | "time" 9 | 10 | "github.com/spf13/viper" 11 | "go.mongodb.org/mongo-driver/v2/mongo" 12 | "go.mongodb.org/mongo-driver/v2/mongo/options" 13 | ) 14 | 15 | var ( 16 | infoLogger *log.Logger 17 | errorLogger *log.Logger 18 | ) 19 | var initialised = false 20 | var mongoCollection *mongo.Collection 21 | 22 | func InitLogger() { 23 | mongoURI := viper.GetString("mongo") 24 | 25 | if len(mongoURI) > 0 { 26 | client, err := mongo.Connect(options.Client().ApplyURI(mongoURI)) 27 | 28 | if err != nil { 29 | panic(err) 30 | } 31 | 32 | mongoCollection = client.Database("bdo-rest-api").Collection("logs") 33 | } 34 | 35 | infoLogger = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime) 36 | errorLogger = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime) 37 | initialised = true 38 | 39 | configPrintOut := fmt.Sprintf("\tPort:\t\t%v\n", viper.GetInt("port")) + 40 | fmt.Sprintf("\tProxies:\t%v\n", viper.GetStringSlice("proxy")) + 41 | fmt.Sprintf("\tVerbosity:\t%v\n", viper.GetBool("verbose")) + 42 | fmt.Sprintf("\tCache TTL:\t%v\n", viper.GetDuration("cachettl")) + 43 | fmt.Sprintf("\tMaint. TTL:\t%v\n", viper.GetDuration("maintenancettl")) + 44 | fmt.Sprintf("\tRate limit:\t%v/min\n", viper.GetInt64("ratelimit")) + 45 | fmt.Sprintf("\tTasks/client:\t%v\n", viper.GetInt("maxtasksperclient")) + 46 | fmt.Sprintf("\tTask retries:\t%v\n", viper.GetInt("taskretries")) + 47 | fmt.Sprintf("\tMongoDB:\t%v", viper.GetString("mongo")) 48 | 49 | Info(fmt.Sprintf("API initialised, configuration loaded:\n%v", configPrintOut)) 50 | } 51 | 52 | func writeToMongo(level, message string) { 53 | if mongoCollection == nil { 54 | return 55 | } 56 | 57 | mongoCollection.InsertOne(context.TODO(), Log{ 58 | CreatedAt: time.Now(), 59 | Level: level, 60 | Message: message, 61 | }) 62 | } 63 | 64 | func Info(message string) { 65 | writeToMongo("INFO", message) 66 | 67 | if !viper.GetBool("verbose") || !initialised { 68 | return 69 | } 70 | 71 | infoLogger.Println(message) 72 | } 73 | 74 | func Error(message string) { 75 | writeToMongo("ERROR", message) 76 | 77 | if !viper.GetBool("verbose") || !initialised { 78 | return 79 | } 80 | 81 | errorLogger.Println(message) 82 | } 83 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "os" 6 | "strconv" 7 | "strings" 8 | "time" 9 | 10 | "bdo-rest-api/handlers" 11 | "bdo-rest-api/logger" 12 | 13 | "github.com/spf13/viper" 14 | ) 15 | 16 | func main() { 17 | flagCacheTTL := flag.Uint("cachettl", 180, "Cache TTL in minutes") 18 | flagMaintenanceTTL := flag.Uint("maintenancettl", 5, "Allows to limit how frequently scraper can check for maintenance end in minutes") 19 | flagMongo := flag.String("mongo", "", "MongoDB connection string for loggig") 20 | flagPort := flag.Uint("port", 8001, "Port to catch requests on") 21 | flagProxy := flag.String("proxy", "", "Open proxy address to make requests to BDO servers") 22 | flagRateLimit := flag.Uint64("ratelimit", 512, "Maximum number of requests per minute per IP") 23 | flagVerbose := flag.Bool("verbose", false, "Print out additional logs into stdout") 24 | flagTaskRetries := flag.Uint("taskretries", 3, "Number of retries for a scraping task") 25 | flagMaxTasksPerClient := flag.Uint("maxtasksperclient", 5, "Maximum number of scraping tasks per client") 26 | flag.Parse() 27 | 28 | // Read port from flags and env 29 | if *flagPort == 8001 && len(os.Getenv("PORT")) > 0 { 30 | port, err := strconv.Atoi(os.Getenv("PORT")) 31 | 32 | if err != nil { 33 | port = 8001 34 | } 35 | 36 | viper.Set("port", port) 37 | } else { 38 | viper.Set("port", int(*flagPort)) 39 | } 40 | 41 | // Read proxies from flags 42 | if len(*flagProxy) > 0 { 43 | viper.Set("proxy", strings.Fields(*flagProxy)) 44 | } else { 45 | viper.Set("proxy", strings.Fields(os.Getenv("PROXY"))) 46 | } 47 | 48 | viper.Set("cachettl", time.Duration(*flagCacheTTL)*time.Minute) 49 | viper.Set("maintenancettl", time.Duration(*flagMaintenanceTTL)*time.Minute) 50 | viper.Set("maxtasksperclient", int(*flagMaxTasksPerClient)) 51 | viper.Set("mongo", *flagMongo) 52 | viper.Set("ratelimit", int64(*flagRateLimit)) 53 | viper.Set("taskretries", int(*flagTaskRetries)) 54 | viper.Set("verbose", *flagVerbose) 55 | 56 | logger.InitLogger() 57 | handlers.ListenAndServe() 58 | } 59 | -------------------------------------------------------------------------------- /middleware/CreateStack.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import "net/http" 4 | 5 | type Middleware func(http.Handler) http.Handler 6 | 7 | func CreateStack(xs ...Middleware) Middleware { 8 | return func(next http.Handler) http.Handler { 9 | for i := len(xs) - 1; i >= 0; i-- { 10 | x := xs[i] 11 | next = x(next) 12 | } 13 | 14 | return next 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /middleware/GetRateLimitMiddleware.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/ulule/limiter/v3" 7 | "github.com/ulule/limiter/v3/drivers/middleware/stdlib" 8 | "github.com/ulule/limiter/v3/drivers/store/memory" 9 | 10 | "github.com/spf13/viper" 11 | ) 12 | 13 | func GetRateLimitMiddleware() Middleware { 14 | var rate = limiter.Rate{ 15 | Limit: viper.GetInt64("ratelimit"), 16 | Period: time.Minute, 17 | } 18 | var store = memory.NewStore() 19 | var instance = limiter.New(store, rate, limiter.WithClientIPHeader("CF-Connecting-IP")) 20 | 21 | var middleware = stdlib.NewMiddleware(instance) 22 | return middleware.Handler 23 | } 24 | -------------------------------------------------------------------------------- /middleware/GetSetHeadersMiddleware.go: -------------------------------------------------------------------------------- 1 | package middleware 2 | 3 | import ( 4 | "net/http" 5 | "time" 6 | ) 7 | 8 | func GetSetHeadersMiddleware() Middleware { 9 | var setHeaders = func(next http.Handler) http.Handler { 10 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 11 | w.Header().Set("Access-Control-Allow-Origin", "*") 12 | w.Header().Set("Content-Type", "application/json") 13 | w.Header().Set("Date", time.Now().Format(time.RFC1123Z)) 14 | 15 | next.ServeHTTP(w, r) 16 | }) 17 | } 18 | 19 | return setHeaders 20 | } 21 | -------------------------------------------------------------------------------- /models/Character.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type Character struct { 4 | Name string `json:"name"` 5 | Class string `json:"class"` 6 | Main bool `json:"main,omitempty"` 7 | Level uint8 `json:"level,omitempty"` 8 | } 9 | -------------------------------------------------------------------------------- /models/GuildProfile.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "time" 4 | 5 | type GuildProfile struct { 6 | Name string `json:"name"` 7 | Region string `json:"region,omitempty"` 8 | CreatedOn *time.Time `json:"createdOn,omitempty"` 9 | Master *Profile `json:"master,omitempty"` 10 | Population uint8 `json:"population,omitempty"` 11 | Occupying string `json:"occupying,omitempty"` 12 | Members []Profile `json:"members,omitempty"` 13 | } 14 | -------------------------------------------------------------------------------- /models/History.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type History struct { 4 | Fish uint `json:"fish"` 5 | Loot uint `json:"loot"` 6 | LootWeight float32 `json:"lootWeight"` 7 | Mobs uint `json:"mobs"` 8 | } 9 | -------------------------------------------------------------------------------- /models/Mastery.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type Mastery struct { 4 | Gathering uint16 `json:"gathering"` 5 | Fishing uint16 `json:"fishing"` 6 | Hunting uint16 `json:"hunting"` 7 | Cooking uint16 `json:"cooking"` 8 | Alchemy uint16 `json:"alchemy"` 9 | Processing uint16 `json:"processing"` 10 | Training uint16 `json:"training"` 11 | Trading uint16 `json:"trading"` 12 | Farming uint16 `json:"farming"` 13 | Sailing uint16 `json:"sailing"` 14 | Barter uint16 `json:"barter"` 15 | } 16 | -------------------------------------------------------------------------------- /models/Profile.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | import "time" 4 | 5 | type Profile struct { 6 | Characters []Character `json:"characters,omitempty"` 7 | CombatFame uint32 `json:"combatFame,omitempty"` 8 | ContributionPoints uint16 `json:"contributionPoints,omitempty"` 9 | CreatedOn *time.Time `json:"createdOn,omitempty"` 10 | Energy uint16 `json:"energy,omitempty"` 11 | FamilyName string `json:"familyName"` 12 | GS uint16 `json:"gs,omitempty"` 13 | Guild *GuildProfile `json:"guild,omitempty"` 14 | History *History `json:"history,omitempty"` 15 | LifeFame uint16 `json:"lifeFame,omitempty"` 16 | Mastery *Mastery `json:"mastery,omitempty"` 17 | Privacy int8 `json:"privacy,omitempty"` 18 | ProfileTarget string `json:"profileTarget"` 19 | Region string `json:"region,omitempty"` 20 | SpecLevels *Specs `json:"specLevels,omitempty"` 21 | } 22 | -------------------------------------------------------------------------------- /models/Specs.go: -------------------------------------------------------------------------------- 1 | package models 2 | 3 | type Specs struct { 4 | Gathering string `json:"gathering"` 5 | Fishing string `json:"fishing"` 6 | Hunting string `json:"hunting"` 7 | Cooking string `json:"cooking"` 8 | Alchemy string `json:"alchemy"` 9 | Processing string `json:"processing"` 10 | Training string `json:"training"` 11 | Trading string `json:"trading"` 12 | Farming string `json:"farming"` 13 | Sailing string `json:"sailing"` 14 | Barter string `json:"barter"` 15 | } 16 | -------------------------------------------------------------------------------- /scraper/GetCloseTime.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/spf13/viper" 7 | ) 8 | 9 | var lastCloseTimes = map[string]time.Time{ 10 | "EUNA": {}, 11 | "KR": {}, 12 | "SA": {}, 13 | } 14 | 15 | func GetCloseTime(region string) (isCloseTime bool, expires time.Time) { 16 | // EU and NA use one website 17 | if region == "EU" || region == "NA" { 18 | region = "EUNA" 19 | } 20 | 21 | expires = lastCloseTimes[region].Add(viper.GetDuration("maintenancettl")) 22 | return time.Now().Before(expires), expires 23 | } 24 | 25 | func setCloseTime(region string) { 26 | // EU and NA use one website 27 | if region == "EU" || region == "NA" { 28 | region = "EUNA" 29 | } 30 | 31 | lastCloseTimes[region] = time.Now() 32 | } 33 | 34 | func GetLastCloseTimes() map[string]time.Time { 35 | return map[string]time.Time{ 36 | "EU": lastCloseTimes["EUNA"], 37 | "KR": lastCloseTimes["KR"], 38 | "NA": lastCloseTimes["EUNA"], 39 | "SA": lastCloseTimes["SA"], 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /scraper/extractProfileTarget.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "net/url" 5 | ) 6 | 7 | func extractProfileTarget(link string) string { 8 | u, _ := url.Parse(link) 9 | m, _ := url.ParseQuery(u.RawQuery) 10 | return m["profileTarget"][0] 11 | } 12 | -------------------------------------------------------------------------------- /scraper/scrapeAdventurer.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "regexp" 7 | "strconv" 8 | "strings" 9 | 10 | "github.com/gocolly/colly/v2" 11 | 12 | "bdo-rest-api/cache" 13 | "bdo-rest-api/models" 14 | "bdo-rest-api/translators" 15 | "bdo-rest-api/utils" 16 | ) 17 | 18 | func scrapeAdventurer(body *colly.HTMLElement, region, profileTarget string) { 19 | status := http.StatusNotFound 20 | profile := models.Profile{ 21 | ProfileTarget: profileTarget, 22 | Region: region, // FIXME: This can potentially be wrong e.g. if client requests a NA profile and gives EU as the region 23 | } 24 | 25 | body.ForEachWithBreak(".nick", func(_ int, e *colly.HTMLElement) bool { 26 | profile.FamilyName = e.Text 27 | status = http.StatusOK 28 | return false 29 | }) 30 | 31 | body.ForEachWithBreak(".lock", func(_ int, _ *colly.HTMLElement) bool { 32 | // FIXME: This is a remains from granular privacy, 33 | // boolean would be more straightforward now 34 | profile.Privacy = 15 35 | return false 36 | }) 37 | 38 | body.ForEachWithBreak(".profile_detail .desc", func(i int, e *colly.HTMLElement) bool { 39 | switch i { 40 | case 0: 41 | createdOn := utils.ParseDate(e.Text) 42 | profile.CreatedOn = &createdOn 43 | case 1: 44 | text := strings.TrimSpace(e.Text) 45 | translators.TranslateMisc(&text) 46 | 47 | if text != "Not in a guild" { 48 | profile.Guild = &models.GuildProfile{ 49 | Name: text, 50 | } 51 | } 52 | case 2: 53 | if gs, err := strconv.Atoi(e.Text); err == nil { 54 | profile.GS = uint16(gs) 55 | } 56 | case 3: 57 | if energy, err := strconv.Atoi(e.Text); err == nil { 58 | profile.Energy = uint16(energy) 59 | } 60 | case 4: 61 | if contributionPoints, err := strconv.Atoi(e.Text); err == nil { 62 | profile.ContributionPoints = uint16(contributionPoints) 63 | } 64 | } 65 | 66 | return profile.Privacy == 0 67 | }) 68 | 69 | body.ForEachWithBreak(".history_level", func(i int, e *colly.HTMLElement) bool { 70 | if profile.Privacy > 0 { 71 | return false 72 | } 73 | 74 | numberField := strings.Fields(e.Text)[0] 75 | 76 | switch i { 77 | case 0: 78 | profile.History = &models.History{} 79 | if mobs, err := strconv.ParseUint(numberField, 10, 32); err == nil { 80 | profile.History.Mobs = uint(mobs) 81 | } 82 | case 1: 83 | if fish, err := strconv.ParseUint(numberField, 10, 32); err == nil { 84 | profile.History.Fish = uint(fish) 85 | } 86 | case 2: 87 | if loot, err := strconv.ParseUint(numberField, 10, 32); err == nil { 88 | profile.History.Loot = uint(loot) 89 | } 90 | case 3: 91 | dotSeparated := strings.Replace(numberField, ",", ".", 1) 92 | 93 | if lootWeight, err := strconv.ParseFloat(dotSeparated, 32); err == nil { 94 | profile.History.LootWeight = float32(lootWeight) 95 | } 96 | } 97 | 98 | return true 99 | }) 100 | 101 | body.ForEachWithBreak(".spec_level", func(i int, e *colly.HTMLElement) bool { 102 | if profile.Privacy > 0 { 103 | return false 104 | } 105 | 106 | fields := regexp.MustCompile(`(\D+)([0-9]+)`).FindStringSubmatch(e.Text) 107 | wordLevel := strings.Replace(strings.Replace(fields[1], "Lv. ", "", 1), "Nv. ", "", 1) 108 | 109 | if region != "EU" && region != "NA" { 110 | translators.TranslateSpecLevel(&wordLevel) 111 | } 112 | 113 | value := wordLevel + " " + fields[2] 114 | 115 | switch i { 116 | case 0: 117 | profile.SpecLevels = &models.Specs{} 118 | profile.SpecLevels.Gathering = value 119 | case 1: 120 | profile.SpecLevels.Fishing = value 121 | case 2: 122 | profile.SpecLevels.Hunting = value 123 | case 3: 124 | profile.SpecLevels.Cooking = value 125 | case 4: 126 | profile.SpecLevels.Alchemy = value 127 | case 5: 128 | profile.SpecLevels.Processing = value 129 | case 6: 130 | profile.SpecLevels.Training = value 131 | case 7: 132 | profile.SpecLevels.Trading = value 133 | case 8: 134 | profile.SpecLevels.Farming = value 135 | case 9: 136 | profile.SpecLevels.Sailing = value 137 | case 10: 138 | profile.SpecLevels.Barter = value 139 | profile.LifeFame = utils.CalculateLifeFame(profile.SpecLevels) 140 | } 141 | 142 | return true 143 | }) 144 | 145 | body.ForEachWithBreak(".spec_stat", func(i int, e *colly.HTMLElement) bool { 146 | if profile.Privacy > 0 { 147 | return false 148 | } 149 | 150 | loot, err := strconv.ParseUint(strings.TrimSpace(e.Text), 10, 16) 151 | if err != nil { 152 | fmt.Println(err) 153 | return false 154 | } 155 | 156 | value := uint16(loot) 157 | 158 | switch i { 159 | case 0: 160 | profile.Mastery = &models.Mastery{} 161 | profile.Mastery.Gathering = value 162 | case 1: 163 | profile.Mastery.Fishing = value 164 | case 2: 165 | profile.Mastery.Hunting = value 166 | case 3: 167 | profile.Mastery.Cooking = value 168 | case 4: 169 | profile.Mastery.Alchemy = value 170 | case 5: 171 | profile.Mastery.Processing = value 172 | case 6: 173 | profile.Mastery.Training = value 174 | case 7: 175 | profile.Mastery.Trading = value 176 | case 8: 177 | profile.Mastery.Farming = value 178 | case 9: 179 | profile.Mastery.Sailing = value 180 | case 10: 181 | profile.Mastery.Barter = value 182 | } 183 | 184 | return true 185 | }) 186 | 187 | body.ForEach(".character_desc_area", func(_ int, e *colly.HTMLElement) { 188 | character := models.Character{ 189 | Class: e.ChildText(".character_info .character_symbol em:last-child"), 190 | } 191 | 192 | if region != "EU" && region != "NA" { 193 | translators.TranslateClassName(&character.Class) 194 | } 195 | 196 | e.ForEachWithBreak(".selected_label", func(_ int, _ *colly.HTMLElement) bool { 197 | character.Main = true 198 | return false 199 | }) 200 | 201 | if profile.Privacy == 0 { 202 | if level, err := strconv.Atoi(e.ChildText(".character_info span:last-child em")); err == nil { 203 | character.Level = uint8(level) 204 | } 205 | } 206 | 207 | if name := e.ChildText(".character_name"); true { 208 | nameEndIndex := strings.Index(name, "\n") 209 | 210 | if nameEndIndex > -1 { 211 | character.Name = name[:nameEndIndex] 212 | } else { 213 | character.Name = name 214 | } 215 | } 216 | 217 | profile.Characters = append(profile.Characters, character) 218 | }) 219 | 220 | if profile.Privacy == 0 { 221 | profile.CombatFame = utils.CalculateCombatFame(profile.Characters) 222 | } 223 | 224 | cache.Profiles.AddRecord([]string{region, profileTarget}, profile, status, body.Request.Ctx.Get("taskId")) 225 | } 226 | -------------------------------------------------------------------------------- /scraper/scrapeAdventurerSearch.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | 7 | "github.com/gocolly/colly/v2" 8 | 9 | "bdo-rest-api/cache" 10 | "bdo-rest-api/models" 11 | "bdo-rest-api/translators" 12 | ) 13 | 14 | func scrapeAdventurerSearch(body *colly.HTMLElement, region, query, searchType string) { 15 | status := http.StatusNotFound 16 | profiles := make([]models.Profile, 0) 17 | 18 | body.ForEach(".box_list_area li:not(.no_result)", func(_ int, e *colly.HTMLElement) { 19 | status = http.StatusOK 20 | profile := models.Profile{ 21 | FamilyName: e.ChildText(".title a"), 22 | ProfileTarget: extractProfileTarget(e.ChildAttr(".title a", "href")), 23 | Region: region, 24 | } 25 | 26 | if len(e.ChildAttr(".state a", "href")) > 0 { 27 | profile.Guild = &models.GuildProfile{ 28 | Name: e.ChildText(".state a"), 29 | } 30 | } 31 | 32 | // Sometimes site displays text "You have not set your main character." 33 | // instead of a character 34 | if len(e.ChildText(".name")) > 0 { 35 | profile.Characters = make([]models.Character, 1) 36 | 37 | profile.Characters[0].Class = e.ChildText(".name") 38 | profile.Characters[0].Name = e.ChildText(".text") 39 | 40 | if profile.Region != "EU" && profile.Region != "NA" { 41 | translators.TranslateClassName(&profile.Characters[0].Class) 42 | } 43 | 44 | if level, err := strconv.Atoi(e.ChildText(".level")[3:]); err == nil { 45 | profile.Characters[0].Level = uint8(level) 46 | } 47 | } 48 | 49 | profiles = append(profiles, profile) 50 | }) 51 | 52 | cache.ProfileSearch.AddRecord([]string{region, query, searchType}, profiles, status, body.Request.Ctx.Get("taskId")) 53 | } 54 | -------------------------------------------------------------------------------- /scraper/scrapeGuild.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | "strings" 7 | 8 | "github.com/gocolly/colly/v2" 9 | 10 | "bdo-rest-api/cache" 11 | "bdo-rest-api/models" 12 | "bdo-rest-api/utils" 13 | ) 14 | 15 | func scrapeGuild(body *colly.HTMLElement, region, guildName string) { 16 | status := http.StatusNotFound 17 | guildProfile := models.GuildProfile{ 18 | Region: region, 19 | } 20 | 21 | body.ForEachWithBreak(".guild_name p", func(_ int, e *colly.HTMLElement) bool { 22 | if guildProfile.Name = e.Text; guildProfile.Name != "" { 23 | status = http.StatusOK 24 | } 25 | 26 | return false 27 | }) 28 | 29 | body.ForEachWithBreak(".line_list.mob_none .desc", func(_ int, e *colly.HTMLElement) bool { 30 | createdOn := utils.ParseDate(e.Text) 31 | guildProfile.CreatedOn = &createdOn 32 | return false 33 | }) 34 | 35 | body.ForEachWithBreak(".line_list:not(.mob_none) li:nth-child(2) .desc .text a", func(_ int, e *colly.HTMLElement) bool { 36 | guildProfile.Master = &models.Profile{ 37 | FamilyName: e.Text, 38 | ProfileTarget: extractProfileTarget(e.Attr("href")), 39 | } 40 | return false 41 | }) 42 | 43 | body.ForEachWithBreak(".line_list:not(.mob_none) li:nth-child(3) em", func(_ int, e *colly.HTMLElement) bool { 44 | population, _ := strconv.Atoi(e.Text) 45 | guildProfile.Population = uint8(population) 46 | return false 47 | }) 48 | 49 | body.ForEachWithBreak(".line_list:not(.mob_none) li:last-child .desc", func(_ int, e *colly.HTMLElement) bool { 50 | text := strings.TrimSpace(e.Text) 51 | if text != "None" && text != "N/A" && text != "없음" { 52 | guildProfile.Occupying = text 53 | } 54 | return false 55 | }) 56 | 57 | body.ForEach(".box_list_area .adventure_list_table a", func(_ int, e *colly.HTMLElement) { 58 | member := models.Profile{ 59 | FamilyName: e.Text, 60 | ProfileTarget: extractProfileTarget(e.Attr("href")), 61 | } 62 | 63 | guildProfile.Members = append(guildProfile.Members, member) 64 | }) 65 | 66 | cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskId")) 67 | } 68 | -------------------------------------------------------------------------------- /scraper/scrapeGuildSearch.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "net/http" 5 | "strconv" 6 | 7 | "github.com/gocolly/colly/v2" 8 | 9 | "bdo-rest-api/cache" 10 | "bdo-rest-api/models" 11 | "bdo-rest-api/utils" 12 | ) 13 | 14 | func scrapeGuildSearch(body *colly.HTMLElement, region, query string) { 15 | status := http.StatusNotFound 16 | guildProfiles := make([]models.GuildProfile, 0) 17 | 18 | body.ForEach(".box_list_area li:not(.no_result)", func(_ int, e *colly.HTMLElement) { 19 | createdOn := utils.ParseDate(e.ChildText(".date")) 20 | status = http.StatusOK 21 | 22 | guildProfile := models.GuildProfile{ 23 | Name: e.ChildText(".guild_title a"), 24 | Region: region, 25 | Master: &models.Profile{ 26 | FamilyName: e.ChildText(".guild_info a"), 27 | ProfileTarget: extractProfileTarget(e.ChildAttr(".guild_info a", "href")), 28 | }, 29 | CreatedOn: &createdOn, 30 | } 31 | 32 | if membersStr := e.ChildText(".member"); true { 33 | population, _ := strconv.Atoi(membersStr) 34 | guildProfile.Population = uint8(population) 35 | } 36 | 37 | guildProfiles = append(guildProfiles, guildProfile) 38 | }) 39 | 40 | cache.GuildSearch.AddRecord([]string{region, query}, guildProfiles, status, body.Request.Ctx.Get("taskId")) 41 | } 42 | -------------------------------------------------------------------------------- /scraper/scraper.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "fmt" 5 | "hash/crc32" 6 | "maps" 7 | "net/url" 8 | "slices" 9 | "strconv" 10 | "strings" 11 | "time" 12 | 13 | "bdo-rest-api/logger" 14 | "bdo-rest-api/utils" 15 | 16 | colly "github.com/gocolly/colly/v2" 17 | "github.com/gocolly/colly/v2/extensions" 18 | "github.com/gocolly/colly/v2/proxy" 19 | "github.com/spf13/viper" 20 | ) 21 | 22 | var taskQueue *TaskQueue 23 | 24 | func init() { 25 | scraper := colly.NewCollector() 26 | extensions.RandomUserAgent(scraper) 27 | scraper.AllowURLRevisit = true 28 | scraper.SetRequestTimeout(time.Minute / 2) 29 | 30 | scraper.Limit(&colly.LimitRule{ 31 | Delay: time.Second, 32 | RandomDelay: 5 * time.Second, 33 | }) 34 | 35 | if p, err := proxy.RoundRobinProxySwitcher(viper.GetStringSlice("proxy")...); err == nil { 36 | scraper.SetProxyFunc(p) 37 | } 38 | 39 | taskQueue = NewTaskQueue(10000) 40 | taskQueue.SetProcessFunc(func(t Task) { 41 | scraper.Visit(t.URL) 42 | }) 43 | 44 | scraper.OnRequest(func(r *colly.Request) { 45 | query := r.URL.Query() 46 | for _, key := range []string{"taskHash", "taskType", "taskRegion", "taskRetries", "taskClient"} { 47 | r.Ctx.Put(key, query.Get(key)) 48 | query.Del(key) 49 | } 50 | r.URL.RawQuery = query.Encode() 51 | }) 52 | 53 | scraper.OnError(func(r *colly.Response, err error) { 54 | logger.Error(fmt.Sprintf("Error occured while loading %v: %v", r.Request.URL, err)) 55 | taskQueue.ConfirmTaskCompletion(r.Ctx.Get("taskClient"), r.Ctx.Get("taskHash")) 56 | }) 57 | 58 | scraper.OnResponse(func(r *colly.Response) { 59 | logger.Info(fmt.Sprintf("Loaded %v", r.Request.URL)) 60 | }) 61 | 62 | scraper.OnHTML("body", func(body *colly.HTMLElement) { 63 | imperva := false 64 | queryString, _ := url.ParseQuery(body.Request.URL.RawQuery) 65 | taskClient := body.Request.Ctx.Get("taskClient") 66 | taskHash := body.Request.Ctx.Get("taskHash") 67 | taskRegion := body.Request.Ctx.Get("taskRegion") 68 | taskType := body.Request.Ctx.Get("taskType") 69 | 70 | body.ForEachWithBreak("iframe", func(_ int, e *colly.HTMLElement) bool { 71 | imperva = true 72 | return false 73 | }) 74 | 75 | if imperva { 76 | taskRetries, _ := strconv.Atoi(body.Request.Ctx.Get("taskRetries")) 77 | logger.Error(fmt.Sprintf("Hit Imperva while loading %v, retries: %v", body.Request.URL.String(), taskRetries)) 78 | taskQueue.Pause(time.Duration(60-time.Now().Second()) * time.Second) 79 | taskQueue.ConfirmTaskCompletion(taskClient, taskHash) 80 | 81 | if taskRetries < viper.GetInt("taskretries") { 82 | taskQueue.AddTask(taskClient, taskHash, utils.BuildRequest(body.Request.URL.String(), map[string]string{ 83 | "taskRegion": taskRegion, 84 | "taskRetries": strconv.Itoa(taskRetries + 1), 85 | "taskType": taskType, 86 | })) 87 | } 88 | 89 | return 90 | } 91 | 92 | body.ForEachWithBreak(".type_3", func(_ int, e *colly.HTMLElement) bool { 93 | // Request gets redirected to https://www.naeu.playblackdesert.com/en-US/shutdown/closetime?shutDownType=0 94 | // Maybe a better way to detect maintenance would be looking at the URL 95 | setCloseTime(taskRegion) 96 | return false 97 | }) 98 | 99 | if isCloseTime, _ := GetCloseTime(taskRegion); isCloseTime { 100 | taskQueue.ConfirmTaskCompletion(taskClient, taskHash) 101 | return 102 | } 103 | 104 | switch taskType { 105 | case "player": 106 | profileTarget := queryString["profileTarget"][0] 107 | scrapeAdventurer(body, taskRegion, profileTarget) 108 | 109 | case "playerSearch": 110 | query := queryString["searchKeyword"][0] 111 | searchType := queryString["searchType"][0] 112 | scrapeAdventurerSearch(body, taskRegion, query, searchType) 113 | 114 | case "guild": 115 | guildName := queryString["guildName"][0] 116 | scrapeGuild(body, taskRegion, guildName) 117 | 118 | case "guildSearch": 119 | query := queryString["searchText"][0] 120 | scrapeGuildSearch(body, taskRegion, query) 121 | 122 | default: 123 | logger.Error(fmt.Sprintf("Task type %v doesn't match any defined scrapers", taskType)) 124 | } 125 | 126 | taskQueue.ConfirmTaskCompletion(taskClient, taskHash) 127 | }) 128 | } 129 | 130 | func createTask(clientIP, region, taskType string, query map[string]string) (tasksQuantityExceeded bool) { 131 | crc32 := crc32.NewIEEE() 132 | crc32.Write([]byte(strings.Join(append(slices.Sorted(maps.Values(query)), region, taskType), ""))) 133 | hashString := strconv.Itoa(int(crc32.Sum32())) 134 | 135 | if taskQueue.CountQueuedTasksForClient(clientIP) >= viper.GetInt("maxtasksperclient") { 136 | return true 137 | } 138 | 139 | url := fmt.Sprintf( 140 | "https://www.%v/Adventure%v", 141 | map[string]string{ 142 | "EU": "naeu.playblackdesert.com/en-US", 143 | "KR": "kr.playblackdesert.com/ko-KR", 144 | "SA": "sa.playblackdesert.com/pt-BR", 145 | "NA": "naeu.playblackdesert.com/en-US", 146 | }[region], 147 | map[string]string{ 148 | "guild": "/Guild/GuildProfile", 149 | "guildSearch": "/Guild", 150 | "player": "/Profile", 151 | "playerSearch": "", 152 | }[taskType], 153 | ) 154 | 155 | maps.Copy(query, map[string]string{ 156 | "taskRegion": region, 157 | "taskRetries": "0", 158 | "taskType": taskType, 159 | }) 160 | 161 | taskQueue.AddTask(clientIP, hashString, utils.BuildRequest(url, query)) 162 | return false 163 | } 164 | 165 | func EnqueueAdventurer(clientIP, region, profileTarget string) (tasksQuantityExceeded bool) { 166 | return createTask(clientIP, region, "player", map[string]string{ 167 | "profileTarget": profileTarget, 168 | }) 169 | } 170 | 171 | func EnqueueAdventurerSearch(clientIP, region, query, searchType string) (tasksQuantityExceeded bool) { 172 | return createTask(clientIP, region, "playerSearch", map[string]string{ 173 | "Page": "1", 174 | "region": region, 175 | "searchKeyword": query, 176 | "searchType": searchType, 177 | }) 178 | } 179 | 180 | func EnqueueGuild(clientIP, region, name string) (tasksQuantityExceeded bool) { 181 | return createTask(clientIP, region, "guild", map[string]string{ 182 | "guildName": name, 183 | "region": region, 184 | }) 185 | } 186 | 187 | func EnqueueGuildSearch(clientIP, region, query string) (tasksQuantityExceeded bool) { 188 | return createTask(clientIP, region, "guildSearch", map[string]string{ 189 | "page": "1", 190 | "region": region, 191 | "searchText": query, 192 | }) 193 | } 194 | -------------------------------------------------------------------------------- /scraper/taskQueue.go: -------------------------------------------------------------------------------- 1 | package scraper 2 | 3 | import ( 4 | "bdo-rest-api/utils" 5 | "slices" 6 | "sync" 7 | "time" 8 | ) 9 | 10 | type Task struct { 11 | ClientIP string 12 | Hash string 13 | URL string 14 | } 15 | 16 | type TaskQueue struct { 17 | clientIPs map[string]int 18 | hashes []string 19 | mutex sync.Mutex 20 | paused bool 21 | processFunc func(Task) 22 | tasks chan Task 23 | } 24 | 25 | func NewTaskQueue(bufferSize int) *TaskQueue { 26 | queue := &TaskQueue{ 27 | clientIPs: make(map[string]int), 28 | paused: false, 29 | tasks: make(chan Task, bufferSize), 30 | } 31 | go queue.run() 32 | return queue 33 | } 34 | 35 | func (q *TaskQueue) AddTask(clientIP, hash, url string) { 36 | fullURL := utils.BuildRequest(url, map[string]string{ 37 | "taskClient": clientIP, 38 | "taskHash": hash, 39 | }) 40 | 41 | q.mutex.Lock() 42 | if duplicate := slices.Contains(q.hashes, hash); duplicate { 43 | q.mutex.Unlock() 44 | return 45 | } 46 | q.clientIPs[clientIP]++ 47 | q.hashes = append(q.hashes, hash) 48 | q.mutex.Unlock() 49 | 50 | q.tasks <- Task{ 51 | ClientIP: clientIP, 52 | Hash: hash, 53 | URL: fullURL, 54 | } 55 | } 56 | 57 | func (q *TaskQueue) run() { 58 | for task := range q.tasks { 59 | q.mutex.Lock() 60 | for q.paused { 61 | q.mutex.Unlock() 62 | // FIXME: This is probably inefficient af 63 | time.Sleep(time.Second) 64 | q.mutex.Lock() 65 | } 66 | q.mutex.Unlock() 67 | 68 | q.processFunc(task) 69 | } 70 | } 71 | 72 | func (q *TaskQueue) SetProcessFunc(f func(Task)) { 73 | q.mutex.Lock() 74 | q.processFunc = f 75 | q.mutex.Unlock() 76 | } 77 | 78 | func (q *TaskQueue) Pause(t time.Duration) { 79 | q.mutex.Lock() 80 | q.paused = true 81 | q.mutex.Unlock() 82 | 83 | time.Sleep(t) 84 | 85 | q.mutex.Lock() 86 | q.paused = false 87 | q.mutex.Unlock() 88 | } 89 | 90 | func (q *TaskQueue) CountQueuedTasksForClient(clientIP string) (count int) { 91 | q.mutex.Lock() 92 | count = max(0, q.clientIPs[clientIP]) 93 | q.mutex.Unlock() 94 | 95 | return 96 | } 97 | 98 | func (q *TaskQueue) ConfirmTaskCompletion(clientIP string, hash string) { 99 | q.mutex.Lock() 100 | q.clientIPs[clientIP] = max(0, q.clientIPs[clientIP]-1) 101 | for i := slices.Index(q.hashes, hash); i != -1; i = slices.Index(q.hashes, hash) { 102 | q.hashes = slices.Delete(q.hashes, i, i+1) 103 | } 104 | q.mutex.Unlock() 105 | } 106 | -------------------------------------------------------------------------------- /translators/TranslateClassName.go: -------------------------------------------------------------------------------- 1 | package translators 2 | 3 | var classNameTranslationMap = map[string]string{ 4 | "Arqueiro": "Archer", 5 | "Bruxa": "Witch", 6 | "Caçadora": "Ranger", 7 | "Cavaleira das Trevas": "Dark Knight", 8 | "Cavaleira Negra": "Dark Knight", 9 | "Corsária": "Corsair", 10 | "Do-Sa": "Dosa", 11 | "Domadora": "Tamer", 12 | "Erudita": "Scholar", 13 | "Erudite": "Scholar", 14 | "Feiticeira": "Sorceress", 15 | "Guardiã": "Guardian", 16 | "Guerreiro": "Warrior", 17 | "Lutador": "Striker", 18 | "Maga": "Witch", 19 | "Mago": "Wizard", 20 | "Me-Gu": "Maegu", 21 | "Mística": "Mystic", 22 | "Musah": "Musa", 23 | "Sábio": "Sage", 24 | "Sagitário": "Archer", 25 | "Valquíria": "Valkyrie", 26 | "Wu-Sa": "Woosa", 27 | "가디언": "Guardian", 28 | "격투가": "Striker", 29 | "금수랑": "Tamer", 30 | "노바": "Nova", 31 | "닌자": "Ninja", 32 | "다크나이트": "Dark Knight", 33 | "데드아이": "Deadeye", 34 | "도사": "Dosa", 35 | "드라카니아": "Drakania", 36 | "란": "Lahn", 37 | "레인저": "Ranger", 38 | "매구": "Maegu", 39 | "매화": "Maehwa", 40 | "무사": "Musa", 41 | "미스틱": "Mystic", 42 | "발키리": "Valkyrie", 43 | "샤이": "Shai", 44 | "세이지": "Sage", 45 | "소서러": "Sorceress", 46 | "스칼라": "Scholar", 47 | "아처": "Archer", 48 | "우사": "Woosa", 49 | "워리어": "Warrior", 50 | "위자드": "Wizard", 51 | "위치": "Witch", 52 | "자이언트": "Berserker", 53 | "커세어": "Corsair", 54 | "쿠노이치": "Kunoichi", 55 | "하사신": "Hashashin", 56 | } 57 | 58 | func TranslateClassName(className *string) { 59 | if val, ok := classNameTranslationMap[*className]; ok { 60 | *className = val 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /translators/TranslateMisc.go: -------------------------------------------------------------------------------- 1 | package translators 2 | 3 | var miscTranslationMap = map[string]string{ 4 | "Não está alistado em nenhuma guilda.": "Not in a guild", 5 | "가입된 길드가 없습니다.": "Not in a guild", 6 | } 7 | 8 | func TranslateMisc(guildMembershipStatus *string) { 9 | if val, ok := miscTranslationMap[*guildMembershipStatus]; ok { 10 | *guildMembershipStatus = val 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /translators/TranslateSpecLevel.go: -------------------------------------------------------------------------------- 1 | package translators 2 | 3 | var specLevelTranslationMap = map[string]string{ 4 | "Aprendiz": "Apprentice", 5 | "Artesão": "Artisan", 6 | "Hábil": "Skilled", 7 | "Iniciante": "Beginner", 8 | "Mestre": "Master", 9 | "Novato": "Beginner", 10 | "Proficiente": "Skilled", 11 | "Profissional": "Professional", 12 | "견습": "Apprentice", 13 | "숙련": "Skilled", 14 | "장인": "Artisan", 15 | "전문": "Professional", 16 | "초급": "Beginner", 17 | "명장": "Master", 18 | "도인": "Guru", 19 | } 20 | 21 | func TranslateSpecLevel(specLevel *string) { 22 | if val, ok := specLevelTranslationMap[*specLevel]; ok { 23 | *specLevel = val 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /utils/BuildRequest.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "net/url" 4 | 5 | func BuildRequest(urlString string, queryMap map[string]string) string { 6 | url, _ := url.Parse(urlString) 7 | q := url.Query() 8 | 9 | for key, value := range queryMap { 10 | q.Set(key, value) 11 | } 12 | 13 | url.RawQuery = q.Encode() 14 | return url.String() 15 | } 16 | -------------------------------------------------------------------------------- /utils/BuildRequest_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestBuildRequest_NoQueryParams(t *testing.T) { 8 | url := "https://example.com/path" 9 | result := BuildRequest(url, map[string]string{}) 10 | if result != url { 11 | t.Errorf("Expected %s, got %s", url, result) 12 | } 13 | } 14 | 15 | func TestBuildRequest_SingleParam(t *testing.T) { 16 | url := "https://example.com/path" 17 | params := map[string]string{"foo": "bar"} 18 | result := BuildRequest(url, params) 19 | expected := "https://example.com/path?foo=bar" 20 | if result != expected { 21 | t.Errorf("Expected %s, got %s", expected, result) 22 | } 23 | } 24 | 25 | func TestBuildRequest_MultipleParams(t *testing.T) { 26 | url := "https://example.com/path" 27 | params := map[string]string{"foo": "bar", "baz": "qux"} 28 | result := BuildRequest(url, params) 29 | if !(result == "https://example.com/path?baz=qux&foo=bar" || result == "https://example.com/path?foo=bar&baz=qux") { 30 | t.Errorf("Unexpected result: %s", result) 31 | } 32 | } 33 | 34 | func TestBuildRequest_SpecialChars(t *testing.T) { 35 | url := "https://example.com/path" 36 | params := map[string]string{"q": "hello world", "x": "a&b"} 37 | result := BuildRequest(url, params) 38 | if !(result == "https://example.com/path?q=hello+world&x=a%26b" || result == "https://example.com/path?x=a%26b&q=hello+world") { 39 | t.Errorf("Unexpected result: %s", result) 40 | } 41 | } 42 | 43 | func TestBuildRequest_OverrideExistingQuery(t *testing.T) { 44 | url := "https://example.com/path?foo=old" 45 | params := map[string]string{"foo": "new", "bar": "baz"} 46 | result := BuildRequest(url, params) 47 | if !(result == "https://example.com/path?bar=baz&foo=new" || result == "https://example.com/path?foo=new&bar=baz") { 48 | t.Errorf("Unexpected result: %s", result) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /utils/CalculateCombatFame.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "bdo-rest-api/models" 5 | ) 6 | 7 | func CalculateCombatFame(characters []models.Character) (combatFame uint32) { 8 | for _, character := range characters { 9 | if character.Level < 56 { 10 | combatFame += uint32(character.Level) 11 | } else if character.Level < 60 { 12 | combatFame += uint32(character.Level) * 2 13 | } else { 14 | combatFame += uint32(character.Level) * 5 15 | } 16 | } 17 | 18 | return combatFame + 1 19 | } 20 | -------------------------------------------------------------------------------- /utils/CalculateLifeFame.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "bdo-rest-api/models" 5 | "reflect" 6 | "strconv" 7 | "strings" 8 | ) 9 | 10 | func CalculateLifeFame(specs *models.Specs) (lifeFame uint16) { 11 | v := reflect.ValueOf(*specs) 12 | 13 | for i := 0; i < v.NumField(); i++ { 14 | spec := v.Field(i).String() 15 | spaceI := strings.Index(spec, " ") 16 | text := spec[0:spaceI] 17 | number, _ := strconv.Atoi(spec[spaceI+1:]) 18 | 19 | if text == "Professional" { 20 | lifeFame += 90 + uint16(number)*3 21 | } else if text == "Artisan" { 22 | lifeFame += 120 + uint16(number)*3 23 | } else if text == "Master" { 24 | lifeFame += 150 + uint16(number)*3 25 | } else if text == "Guru" { 26 | lifeFame += 240 + uint16(number)*3 27 | } 28 | } 29 | 30 | return lifeFame + 1 31 | } 32 | -------------------------------------------------------------------------------- /utils/CalculateLifeFame_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "bdo-rest-api/models" 5 | "testing" 6 | ) 7 | 8 | func TestCalculateLifeFame(t *testing.T) { 9 | tests := []struct { 10 | input models.Specs 11 | expected uint16 12 | }{ 13 | { 14 | input: models.Specs{"Artisan 6", "Professional 4", "Artisan 1", "Master 6", "Professional 7", "Artisan 8", "Professional 10", "Apprentice 9", "Skilled 4", "Apprentice 4", "Beginner 1"}, 15 | expected: 907, 16 | }, 17 | { 18 | input: models.Specs{"Guru 7", "Skilled 5", "Beginner 8", "Guru 52", "Guru 27", "Guru 35", "Artisan 3", "Apprentice 7", "Guru 15", "Geginner 6", "Beginner 1"}, 19 | expected: 1738, 20 | }, 21 | { 22 | input: models.Specs{"Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1", "Beginner 1"}, 23 | expected: 1, 24 | }, 25 | } 26 | 27 | for _, test := range tests { 28 | result := CalculateLifeFame(&test.input) 29 | if result != test.expected { 30 | t.Errorf("Input: %v, Expected: %v, Got: %v", test.input, test.expected, result) 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /utils/FormatDateForHeaders.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import "time" 4 | 5 | func FormatDateForHeaders(date time.Time) string { 6 | return date.Format(time.RFC1123Z) 7 | } 8 | -------------------------------------------------------------------------------- /utils/FormatDateForHeaders_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func TestFormatDateForHeaders(t *testing.T) { 9 | // Use a fixed date for deterministic output 10 | dt := time.Date(2025, 4, 19, 8, 6, 53, 0, time.FixedZone("CEST", 2*60*60)) 11 | expected := dt.Format(time.RFC1123Z) 12 | got := FormatDateForHeaders(dt) 13 | if got != expected { 14 | t.Errorf("FormatDateForHeaders(%v) = %q; want %q", dt, got, expected) 15 | } 16 | 17 | // Check UTC 18 | dtUTC := time.Date(2025, 4, 19, 6, 6, 53, 0, time.UTC) 19 | expectedUTC := dtUTC.Format(time.RFC1123Z) 20 | gotUTC := FormatDateForHeaders(dtUTC) 21 | if gotUTC != expectedUTC { 22 | t.Errorf("FormatDateForHeaders(%v) = %q; want %q", dtUTC, gotUTC, expectedUTC) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /utils/ParseDate.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "strings" 5 | "time" 6 | ) 7 | 8 | func ParseDate(text string) time.Time { 9 | var format string 10 | if strings.Contains(text, ".") { 11 | // KR 12 | format = "2006.01.02" 13 | } else if strings.Contains(text, "/") { 14 | // SA 15 | format = "02/01/2006 (UTC-3)" 16 | } else { 17 | // NAEU 18 | format = "Jan 2, 2006 (UTC)" 19 | } 20 | 21 | if parsed, err := time.Parse(format, strings.TrimSpace(text)); nil == err { 22 | return parsed 23 | } 24 | 25 | return time.Time{} 26 | } 27 | -------------------------------------------------------------------------------- /utils/ParseDate_test.go: -------------------------------------------------------------------------------- 1 | package utils 2 | 3 | import ( 4 | "testing" 5 | "time" 6 | ) 7 | 8 | func TestParseDate(t *testing.T) { 9 | tests := []struct { 10 | input string 11 | expected time.Time 12 | }{ 13 | // Valid date formats 14 | { 15 | input: "2023.08.01", 16 | expected: time.Date(2023, time.August, 1, 0, 0, 0, 0, time.UTC), 17 | }, 18 | { 19 | input: "01/08/2023 (UTC-3)", 20 | expected: time.Date(2023, time.August, 1, 3, 0, 0, 0, time.UTC), 21 | }, 22 | { 23 | input: "Aug 1, 2023 (UTC)", 24 | expected: time.Date(2023, time.August, 1, 0, 0, 0, 0, time.UTC), 25 | }, 26 | 27 | // Invalid date formats 28 | { 29 | input: "2023.13.31", // Invalid month 30 | expected: time.Time{}, 31 | }, 32 | { 33 | input: "07-31/2023", // Invalid separator 34 | expected: time.Time{}, 35 | }, 36 | 37 | // Empty input 38 | { 39 | input: "", 40 | expected: time.Time{}, 41 | }, 42 | } 43 | 44 | for _, test := range tests { 45 | result := ParseDate(test.input) 46 | if !result.Equal(test.expected) { 47 | t.Errorf("Input: %v, Expected: %v, Got: %v", test.input, test.expected, result) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /validators/ValidateAdventurerNameQueryParam.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "unicode" 7 | ) 8 | 9 | // The naming policies in BDO are fucked up 10 | // This function only checks the length and allowed symbols 11 | func ValidateAdventurerNameQueryParam(query []string, region string, searchType string) (name string, ok bool, errorMessage string) { 12 | if 1 > len(query) { 13 | return "", false, "Adventurer name is missing from request" 14 | } 15 | 16 | minLength := map[string]int{ 17 | "EU1": 2, 18 | "EU2": 1, 19 | "KR1": 2, 20 | "KR2": 1, 21 | "NA1": 2, 22 | "NA2": 1, 23 | "SA1": 2, 24 | "SA2": 2, 25 | }[region+searchType] 26 | 27 | name = strings.ToLower(query[0]) 28 | 29 | if len(name) < minLength || len(name) > 16 { 30 | return name, false, fmt.Sprintf("Adventurer name should be between %v and 16 symbols long", minLength) 31 | } 32 | 33 | // Returns false for allowed characters 34 | // and true for everything else 35 | f := func(r rune) bool { 36 | // Numbers 37 | if unicode.IsNumber(r) { 38 | return false 39 | } 40 | 41 | // Latin letters 42 | if unicode.Is(unicode.Latin, r) { 43 | return false 44 | } 45 | 46 | // Underscore 47 | if r == '_' { 48 | return false 49 | } 50 | 51 | // Korean characters 52 | if unicode.Is(unicode.Hangul, r) { 53 | return false 54 | } 55 | 56 | return true 57 | } 58 | 59 | if i := strings.IndexFunc(name, f); i != -1 { 60 | return name, false, fmt.Sprintf("Adventurer name contains a forbidden symbol at position %v: %q", i+1, query[0][i]) 61 | } 62 | 63 | return name, true, "" 64 | } 65 | -------------------------------------------------------------------------------- /validators/ValidateAdventurerNameQueryParam_test.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import "testing" 4 | 5 | func TestValidateAdventurerNameQueryParam(t *testing.T) { 6 | tests := []struct { 7 | expectedName string 8 | expectedOk bool 9 | expectedMessage string 10 | input []string 11 | region string 12 | searchType string 13 | }{ 14 | {input: []string{"1Number"}, region: "EU", searchType: "1", expectedName: "1number", expectedOk: true, expectedMessage: ""}, 15 | {input: []string{"Adventurer_123"}, region: "EU", searchType: "1", expectedName: "adventurer_123", expectedOk: true, expectedMessage: ""}, 16 | {input: []string{"JohnDoe"}, region: "EU", searchType: "1", expectedName: "johndoe", expectedOk: true, expectedMessage: ""}, 17 | {input: []string{"Name1", "Name2"}, region: "EU", searchType: "1", expectedName: "name1", expectedOk: true, expectedMessage: ""}, 18 | {input: []string{"고대신"}, region: "EU", searchType: "1", expectedName: "고대신", expectedOk: true, expectedMessage: ""}, 19 | 20 | {input: []string{""}, region: "EU", searchType: "1", expectedName: "", expectedOk: false, expectedMessage: "Adventurer name should be between 2 and 16 symbols long"}, 21 | {input: []string{"With Spaces"}, region: "EU", searchType: "1", expectedName: "with spaces", expectedOk: false, expectedMessage: "Adventurer name contains a forbidden symbol at position 5: ' '"}, 22 | {input: []string{"AdventurerNameTooLong12345"}, region: "EU", searchType: "1", expectedName: "adventurernametoolong12345", expectedOk: false, expectedMessage: "Adventurer name should be between 2 and 16 symbols long"}, 23 | {input: []string{"Name$"}, region: "EU", searchType: "1", expectedName: "name$", expectedOk: false, expectedMessage: "Adventurer name contains a forbidden symbol at position 5: '$'"}, 24 | {input: []string{}, region: "EU", searchType: "1", expectedName: "", expectedOk: false, expectedMessage: "Adventurer name is missing from request"}, 25 | 26 | {input: []string{""}, region: "SA", searchType: "2", expectedName: "", expectedOk: false, expectedMessage: "Adventurer name should be between 2 and 16 symbols long"}, 27 | {input: []string{"Ad"}, region: "SA", searchType: "2", expectedName: "ad", expectedOk: true, expectedMessage: ""}, 28 | } 29 | 30 | for _, test := range tests { 31 | name, ok, message := ValidateAdventurerNameQueryParam(test.input, test.region, test.searchType) 32 | if name != test.expectedName || ok != test.expectedOk || message != test.expectedMessage { 33 | t.Errorf("Input: %v %v, Expected: %v %v %v, Got: %v %v %v", test.input, test.region, test.expectedName, test.expectedOk, test.expectedMessage, name, ok, message) 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /validators/ValidateGuildNameQueryParam.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | "unicode" 7 | ) 8 | 9 | // The naming policies in BDO are fucked up 10 | // This function only checks the length and allowed symbols 11 | // I also assumed that the allowed symbols are the same as for adventurer names 12 | func ValidateGuildNameQueryParam(query []string) (guildName string, ok bool, errorMessage string) { 13 | if 1 > len(query) { 14 | return "", false, "Guild name is missing from request" 15 | } 16 | 17 | guildName = strings.ToLower(query[0]) 18 | 19 | if len(guildName) < 2 { 20 | return guildName, false, "Guild name can't be shorter than 2 symbols" 21 | } 22 | 23 | // Returns false for allowed characters 24 | // and true for everything else 25 | f := func(r rune) bool { 26 | // Numbers 27 | if unicode.IsNumber(r) { 28 | return false 29 | } 30 | 31 | // Latin letters 32 | if unicode.Is(unicode.Latin, r) { 33 | return false 34 | } 35 | 36 | // Underscore 37 | if r == '_' { 38 | return false 39 | } 40 | 41 | // Korean characters 42 | if unicode.Is(unicode.Hangul, r) { 43 | return false 44 | } 45 | 46 | return true 47 | } 48 | 49 | if i := strings.IndexFunc(guildName, f); i != -1 { 50 | return guildName, false, fmt.Sprintf("Guild name contains a forbidden symbol at position %v: %q", i+1, guildName[i]) 51 | } 52 | 53 | return guildName, true, "" 54 | } 55 | -------------------------------------------------------------------------------- /validators/ValidateGuildNameQueryParam_test.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import "testing" 4 | 5 | func TestValidateGuildNameQueryParam(t *testing.T) { 6 | tests := []struct { 7 | expectedName string 8 | expectedOk bool 9 | expectedMessage string 10 | input []string 11 | }{ 12 | {input: []string{"1NumberGuild"}, expectedName: "1numberguild", expectedOk: true, expectedMessage: ""}, // Contains a number 13 | {input: []string{"Adventure_Guild"}, expectedName: "adventure_guild", expectedOk: true, expectedMessage: ""}, 14 | {input: []string{"FirstGuild", "SecondGuild"}, expectedName: "firstguild", expectedOk: true, expectedMessage: ""}, 15 | {input: []string{"MyGuild"}, expectedName: "myguild", expectedOk: true, expectedMessage: ""}, 16 | {input: []string{"고대신"}, expectedName: "고대신", expectedOk: true, expectedMessage: ""}, // Guild name with Korean characters 17 | 18 | {input: []string{""}, expectedName: "", expectedOk: false, expectedMessage: "Guild name can't be shorter than 2 symbols"}, 19 | {input: []string{"A Guild With Spaces"}, expectedName: "a guild with spaces", expectedOk: false, expectedMessage: "Guild name contains a forbidden symbol at position 2: ' '"}, 20 | {input: []string{"Some$"}, expectedName: "some$", expectedOk: false, expectedMessage: "Guild name contains a forbidden symbol at position 5: '$'"}, 21 | {input: []string{"x"}, expectedName: "x", expectedOk: false, expectedMessage: "Guild name can't be shorter than 2 symbols"}, 22 | {input: []string{}, expectedName: "", expectedOk: false, expectedMessage: "Guild name is missing from request"}, 23 | } 24 | 25 | for _, test := range tests { 26 | name, ok, message := ValidateGuildNameQueryParam(test.input) 27 | if name != test.expectedName || ok != test.expectedOk || message != test.expectedMessage { 28 | t.Errorf("Input: %v, Expected: %v %v %v, Got: %v %v %v", test.input, test.expectedName, test.expectedOk, test.expectedMessage, name, ok, message) 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /validators/ValidateProfileTargetQueryParam.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | // Check that the length is at least 150 characters 4 | // I don't actually know how long it should be, but the length varies 5 | func ValidateProfileTargetQueryParam(query []string) (profileTarget string, ok bool, errorMessage string) { 6 | if 1 > len(query) { 7 | return "", false, "Profile target is missing from the request" 8 | } 9 | 10 | if ok := len(query[0]) >= 150; ok { 11 | return query[0], true, "" 12 | } 13 | 14 | return query[0], false, "Profile target has to be at least 150 characters long" 15 | } 16 | -------------------------------------------------------------------------------- /validators/ValidateProfileTargetQueryParam_test.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import "testing" 4 | 5 | func TestValidateProfileTargetQueryParam(t *testing.T) { 6 | tests := []struct { 7 | expectedOk bool 8 | expectedPT string 9 | expectedMessage string 10 | input []string 11 | }{ 12 | // Valid profile targets with lengths >= 150 13 | {input: []string{repeat("A", 150)}, expectedPT: repeat("A", 150), expectedOk: true, expectedMessage: ""}, 14 | {input: []string{repeat("A", 200)}, expectedPT: repeat("A", 200), expectedOk: true, expectedMessage: ""}, 15 | 16 | // Invalid profile targets with lengths < 150 17 | {input: []string{""}, expectedPT: "", expectedOk: false, expectedMessage: "Profile target has to be at least 150 characters long"}, 18 | {input: []string{"Short"}, expectedPT: "Short", expectedOk: false, expectedMessage: "Profile target has to be at least 150 characters long"}, 19 | {input: []string{repeat("A", 149)}, expectedPT: repeat("A", 149), expectedOk: false, expectedMessage: "Profile target has to be at least 150 characters long"}, 20 | 21 | // Query param not provided 22 | {input: []string{}, expectedPT: "", expectedOk: false, expectedMessage: "Profile target is missing from the request"}, 23 | 24 | // Several profileTargets provided 25 | {input: []string{repeat("A", 150), repeat("B", 150)}, expectedPT: repeat("A", 150), expectedOk: true, expectedMessage: ""}, 26 | } 27 | 28 | for _, test := range tests { 29 | pT, ok, message := ValidateProfileTargetQueryParam(test.input) 30 | if pT != test.expectedPT || ok != test.expectedOk || message != test.expectedMessage { 31 | t.Errorf("Input: %v, Expected: %v %v %v, Got: %v %v %v", test.input, test.expectedPT, test.expectedOk, test.expectedMessage, pT, ok, message) 32 | } 33 | } 34 | } 35 | 36 | // Helper function to repeat a character n times. 37 | func repeat(s string, n int) string { 38 | var result string 39 | for i := 0; i < n; i++ { 40 | result += s 41 | } 42 | return result 43 | } 44 | -------------------------------------------------------------------------------- /validators/ValidateRegionQueryParam.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import ( 4 | "fmt" 5 | "slices" 6 | "strings" 7 | ) 8 | 9 | func ValidateRegionQueryParam(query []string) (region string, ok bool, errorMessage string) { 10 | if 1 > len(query) { 11 | return "EU", true, "" 12 | } 13 | 14 | region = strings.ToUpper(query[0]) 15 | 16 | // TODO: Add KR region once the translations are ready 17 | if !slices.Contains([]string{"EU", "NA", "SA", "KR"}, region) { 18 | return region, false, fmt.Sprintf("Region %v is not supported", region) 19 | } 20 | 21 | return region, true, "" 22 | } 23 | -------------------------------------------------------------------------------- /validators/ValidateRegionQueryParam_test.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import ( 4 | "testing" 5 | ) 6 | 7 | func TestValidateRegionQueryParameter(t *testing.T) { 8 | tests := []struct { 9 | expectedOk bool 10 | expectedRegion string 11 | expectedMessage string 12 | input []string 13 | }{ 14 | {input: []string{}, expectedRegion: "EU", expectedOk: true, expectedMessage: ""}, 15 | {input: []string{"NA"}, expectedRegion: "NA", expectedOk: true, expectedMessage: ""}, 16 | {input: []string{"na"}, expectedRegion: "NA", expectedOk: true, expectedMessage: ""}, 17 | {input: []string{"SA"}, expectedRegion: "SA", expectedOk: true, expectedMessage: ""}, 18 | {input: []string{"EU"}, expectedRegion: "EU", expectedOk: true, expectedMessage: ""}, 19 | {input: []string{"ABC"}, expectedRegion: "ABC", expectedOk: false, expectedMessage: "Region ABC is not supported"}, 20 | {input: []string{"KR", "SA"}, expectedRegion: "KR", expectedOk: true, expectedMessage: ""}, // Takes the first region in case of multiple regions 21 | } 22 | 23 | for _, test := range tests { 24 | result, ok, message := ValidateRegionQueryParam(test.input) 25 | if result != test.expectedRegion || ok != test.expectedOk || message != test.expectedMessage { 26 | t.Errorf("For input %v, expected %v %v %v, but got %v %v %v", test.input, test.expectedRegion, test.expectedOk, test.expectedMessage, result, ok, message) 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /validators/ValidateSearchTypeQueryParam.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | func ValidateSearchTypeQueryParam(query []string) string { 4 | if 1 > len(query) { 5 | return "2" 6 | } 7 | 8 | if query[0] == "characterName" { 9 | return "1" 10 | } 11 | 12 | return "2" 13 | } 14 | -------------------------------------------------------------------------------- /validators/ValidateSearchTypeQueryParam_test.go: -------------------------------------------------------------------------------- 1 | package validators 2 | 3 | import "testing" 4 | 5 | func TestValidateSearchTypeQueryParam(t *testing.T) { 6 | tests := []struct { 7 | expected string 8 | input []string 9 | }{ 10 | {input: []string{}, expected: "2"}, 11 | {input: []string{"characterName"}, expected: "1"}, 12 | {input: []string{"invalidType"}, expected: "2"}, 13 | {input: []string{"familyName"}, expected: "2"}, 14 | } 15 | 16 | for _, test := range tests { 17 | result := ValidateSearchTypeQueryParam(test.input) 18 | if result != test.expected { 19 | t.Errorf("For input %v, expected %v, but got %v", test.input, test.expected, result) 20 | } 21 | } 22 | } 23 | --------------------------------------------------------------------------------