-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 🎸 upgrade cobalt from v7 to v10 https://github.com/imputnet/cobalt/tree/main * refactor: 💡 move dir * chore: 🤖 update zeabur templates
- Loading branch information
1 parent
4e86a66
commit 38cdc28
Showing
13 changed files
with
159 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,28 @@ | ||
services: | ||
cobalt-api: | ||
image: ghcr.io/imputnet/cobalt:10 | ||
|
||
init: true | ||
read_only: true | ||
restart: unless-stopped | ||
|
||
ports: | ||
- 9001:9000/tcp | ||
environment: | ||
API_URL: "http://localhost:9001/" | ||
|
||
typesense: | ||
image: typesense/typesense:27.1 | ||
|
||
restart: on-failure | ||
hostname: typesense | ||
|
||
ports: | ||
- "8100:8108" | ||
- "8101:8108" | ||
volumes: | ||
- ./data/typesense-data:/data | ||
command: "--data-dir /data --api-key=xyz --enable-cors" | ||
healthcheck: | ||
test: ["CMD", "curl", "-f", "http://localhost:8100/health"] | ||
test: ["CMD", "curl", "-f", "http://localhost:8101/health"] | ||
interval: 30s | ||
timeout: 10s | ||
retries: 5 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
lib/tj/url_helper.ex → lib/save_it/small_helper/url_helper.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
defmodule SmallSdk.Cobalt do | ||
require Logger | ||
|
||
import SaveIt.SmallHelper.UrlHelper, only: [validate_url!: 1] | ||
|
||
def get_download_url(text) do | ||
url = String.split(text, "?") |> hd() | ||
|
||
req = build_request("/") | ||
res = Req.post(req, json: %{url: url}) | ||
|
||
body = handle_response(res) | ||
|
||
case body do | ||
%{"url" => download_url} -> | ||
{:ok, download_url} | ||
|
||
%{"status" => "picker", "picker" => picker_items} -> | ||
{:ok, url, Enum.map(picker_items, &Map.get(&1, "url"))} | ||
|
||
%{"status" => "error", "text" => msg} -> | ||
Logger.warning("response.body is status error, text: #{msg}") | ||
{:error, msg} | ||
|
||
_ -> | ||
Logger.warning("response.body: #{inspect(body)}") | ||
{:error, "inner service error"} | ||
end | ||
end | ||
|
||
defp get_env() do | ||
api_url = Application.fetch_env!(:save_it, :cobalt_api_url) |> validate_url!() | ||
|
||
{api_url} | ||
end | ||
|
||
defp build_request(path) do | ||
{api_url} = get_env() | ||
|
||
Req.new( | ||
base_url: api_url, | ||
url: path, | ||
headers: [ | ||
{"Accept", "application/json"}, | ||
{"Content-Type", "application/json"} | ||
] | ||
) | ||
end | ||
|
||
@doc """ | ||
Handle response from Cobalt API return body if status is 200..209 | ||
""" | ||
def handle_response({:ok, %{status: status, body: body}}) do | ||
case status do | ||
status when status in 200..209 -> | ||
body | ||
|
||
400 -> | ||
Logger.warning("Bad Request: #{inspect(body)}") | ||
raise "Bad Request" | ||
|
||
401 -> | ||
raise "Unauthorized" | ||
|
||
404 -> | ||
nil | ||
|
||
409 -> | ||
raise "Conflict" | ||
|
||
422 -> | ||
raise "Unprocessable Entity" | ||
|
||
503 -> | ||
raise "Service Unavailable" | ||
|
||
_ -> | ||
Logger.error("Unhandled status code #{status}: #{inspect(body)}") | ||
raise "Unknown error: #{status}" | ||
end | ||
end | ||
|
||
def handle_response({:error, reason}) do | ||
Logger.error("Request failed: #{inspect(reason)}") | ||
raise "Request failed" | ||
end | ||
|
||
def handle_response!(%{status: status, body: body}) do | ||
case status do | ||
status when status in 200..209 -> | ||
body | ||
|
||
status -> | ||
Logger.warning("Request failed with status #{status}: #{inspect(body)}") | ||
raise "Request failed with status #{status}" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
# Zeabur | ||
# SaveIt template on zeabur | ||
|
||
## Typesense Template | ||
- zeabur template: https://zeabur.com/templates/FTAONK | ||
- github: https://github.com/ThaddeusJiang/save_it/ | ||
|
||
## Develop | ||
|
||
```sh | ||
npx zeabur template update -c FTAONK -f typesense-template.yaml | ||
npx zeabur template update -c FTAONK -f template.yaml | ||
``` | ||
|
||
docs: | ||
## Docs | ||
|
||
- https://zeabur.com/docs/template/template-in-code | ||
- [zeabur docs | template ](https://zeabur.com/docs/template/template-in-code) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters