Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): upgrade some deps & fix error #21

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,6 @@ dashboard.help:
dashboard:
$(call dashboard.help)
@echo "\n"
dashboard.apollo:
$(call browse,"$(DASHBOARD_APOLLO_LINK)")
dashboard.pm2:
$(call browse,"$(DASHBOARD_PM2_LINK)")
dashboard.errors:
Expand Down
4 changes: 0 additions & 4 deletions Makefile.include.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ OS := ${shell uname}
BELONG = "coderplanets"
REPO = "coderplanets_server"

DASHBOARD_APOLLO_LINK = "https://engine.apollographql.com/account/gh.mydearxym/services"
DASHBOARD_PM2_LINK = "https://app.pm2.io"
DASHBOARD_ALIYUN_LINK = "https://home.console.aliyun.com/new"
DASHBOARD_SENTRY_LINK = "https://sentry.io/groupher-stack/cps_server_prod"
Expand Down Expand Up @@ -190,9 +189,6 @@ define dashboard.help
@echo "\n"
@echo " [valid dashboard commands]"
@echo " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
@echo " dashboard.apollo : graphql api status provide by apollo engine"
@echo " | $(DASHBOARD_APOLLO_LINK)"
@echo " ................................................................................."
@echo " dashboard.pm2 : pm2 running status"
@echo " | $(DASHBOARD_PM2_LINK)"
@echo " ................................................................................."
Expand Down
2 changes: 1 addition & 1 deletion cover/excoveralls.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion lib/groupher_server_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ defmodule GroupherServerWeb.Router do
Absinthe.Plug.GraphiQL,
schema: GroupherServerWeb.Schema,
json_codec: Jason,
pipeline: {ApolloTracing.Pipeline, :plug},
interface: :playground,
context: %{pubsub: GroupherServerWeb.Endpoint}
)
Expand Down
6 changes: 2 additions & 4 deletions lib/groupher_server_web/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ defmodule GroupherServerWeb.Schema do
scham index
"""
use Absinthe.Schema
# use ApolloTracing
import GroupherServerWeb.Schema.Helper.Imports

alias GroupherServerWeb.Middleware, as: M
Expand Down Expand Up @@ -65,16 +64,15 @@ defmodule GroupherServerWeb.Schema do
end

def middleware(middleware, _field, %{identifier: :query}) do
[ApolloTracing.Middleware.Caching] ++ middleware ++ [M.GeneralError]
middleware ++ [M.GeneralError]
end

def middleware(middleware, _field, %{identifier: :mutation}) do
middleware ++ [M.ChangesetErrors]
end

def middleware(middleware, _field, _object) do
# [ApolloTracing.Middleware.Tracing, ApolloTracing.Middleware.Caching] ++ middleware
[ApolloTracing.Middleware.Tracing] ++ middleware
middleware
end

def plugins do
Expand Down
4 changes: 2 additions & 2 deletions lib/groupher_server_web/schema/Helper/queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule GroupherServerWeb.Schema.Helper.Queries do
field unquote(:"paged_published_#{plural(thread)}"),
unquote(:"paged_#{plural(thread)}") do
arg(:login, non_null(:string))
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))
arg(:thread, unquote(:"#{thread}_thread"), default_value: unquote(thread))

middleware(M.PageSizeProof)
Expand Down Expand Up @@ -79,7 +79,7 @@ defmodule GroupherServerWeb.Schema.Helper.Queries do
field unquote(:"#{action}ed_users"), :paged_users do
arg(:id, non_null(:id))
arg(:thread, :thread, default_value: :post)
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))

middleware(M.PageSizeProof)
resolve(unquote(resolver))
Expand Down
10 changes: 5 additions & 5 deletions lib/groupher_server_web/schema/account/account_queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ defmodule GroupherServerWeb.Schema.Account.Queries do
@desc "anyone can get anyone's subscribed communities"
field :subscribed_communities, :paged_communities do
arg(:login, :string)
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))

middleware(M.PageSizeProof)
resolve(&R.Accounts.subscribed_communities/3)
Expand All @@ -56,7 +56,7 @@ defmodule GroupherServerWeb.Schema.Account.Queries do
@desc "get user's follower"
field :paged_followers, :paged_users do
arg(:login, non_null(:string))
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))

middleware(M.PageSizeProof)
resolve(&R.Accounts.paged_followers/3)
Expand All @@ -65,7 +65,7 @@ defmodule GroupherServerWeb.Schema.Account.Queries do
@desc "get user's follower"
field :paged_followings, :paged_users do
arg(:login, non_null(:string))
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))

middleware(M.PageSizeProof)
resolve(&R.Accounts.paged_followings/3)
Expand Down Expand Up @@ -100,7 +100,7 @@ defmodule GroupherServerWeb.Schema.Account.Queries do
@desc "paged communities which the user it's the editor"
field :moderatorable_communities, :paged_communities do
arg(:login, :string)
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))

middleware(M.PageSizeProof)
resolve(&R.Accounts.moderatorable_communities/3)
Expand All @@ -123,7 +123,7 @@ defmodule GroupherServerWeb.Schema.Account.Queries do
@desc "get paged published article comments"
field :paged_published_comments, :paged_comments do
arg(:login, non_null(:string))
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))
arg(:thread, :thread, default_value: :post)

middleware(M.PageSizeProof)
Expand Down
2 changes: 1 addition & 1 deletion lib/groupher_server_web/schema/billing/billing_queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defmodule GroupherServerWeb.Schema.Billing.Queries do
object :billing_queries do
@desc "get all bills"
field :paged_bill_records, non_null(:paged_bills) do
arg(:filter, non_null(:paged_filter))
arg(:filter, non_null(:pagi_filter))

middleware(M.Authorize, :login)
middleware(M.PageSizeProof)
Expand Down
7 changes: 1 addition & 6 deletions lib/groupher_server_web/schema/cms/cms_metrics.ex
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,6 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do
value(:timeline)
end

@desc "inline members-like filter for dataloader usage"
input_object :members_filter do
field(:first, :integer, default_value: @default_inner_page_size)
end

input_object :comments_filter do
pagination_args()
field(:sort, :inserted_sort_enum, default_value: :asc_inserted)
Expand Down Expand Up @@ -172,7 +167,7 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do
field(:index, :integer)
end

input_object :paged_filter do
input_object :pagi_filter do
@desc "limit of records (default 20), if first > 30, only return 30 at most"
pagination_args()
field(:sort, :sort_enum)
Expand Down
10 changes: 5 additions & 5 deletions lib/groupher_server_web/schema/cms/cms_queries.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do
field :paged_community_subscribers, :paged_users do
arg(:id, :id)
arg(:community, :string)
arg(:filter, :paged_filter)
arg(:filter, :pagi_filter)

middleware(M.PageSizeProof)
resolve(&R.CMS.paged_community_subscribers/3)
Expand All @@ -57,7 +57,7 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do
@desc "paged subscribers of a community"
field :paged_community_moderators, :paged_users do
arg(:id, non_null(:id))
arg(:filter, :paged_filter)
arg(:filter, :pagi_filter)

middleware(M.PageSizeProof)
resolve(&R.CMS.paged_community_moderators/3)
Expand All @@ -73,7 +73,7 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do

@desc "get all categories"
field :paged_categories, :paged_categories do
arg(:filter, :paged_filter)
arg(:filter, :pagi_filter)

middleware(M.PageSizeProof)
resolve(&R.CMS.paged_categories/3)
Expand Down Expand Up @@ -126,7 +126,7 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do
field :paged_comments_participants, :paged_users do
arg(:id, non_null(:id))
arg(:thread, :thread, default_value: :post)
arg(:filter, :paged_filter)
arg(:filter, :pagi_filter)

middleware(M.PageSizeProof)
resolve(&R.CMS.paged_comments_participants/3)
Expand All @@ -152,7 +152,7 @@ defmodule GroupherServerWeb.Schema.CMS.Queries do
field :paged_citing_contents, :paged_citings do
arg(:id, non_null(:id))
arg(:content, :content, default_value: :post)
arg(:filter, :paged_filter)
arg(:filter, :pagi_filter)

resolve(&R.CMS.paged_citing_contents/3)
end
Expand Down
1 change: 0 additions & 1 deletion lib/groupher_server_web/schema/cms/cms_types.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ defmodule GroupherServerWeb.Schema.CMS.Types do
field(:login, :string)
field(:avatar, :string)
field(:nickname, :string)
field(:avatar, :string)
field(:bio, :string)
field(:shortbio, :string)
end
Expand Down
50 changes: 50 additions & 0 deletions lib/helper/oss.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
defmodule Helper.OSS do
@moduledoc """
find city info by ip
refer: https://lbs.amap.com/api/webservice/guide/api/ipconfig/?sug_index=0
"""
use Tesla, only: [:get]
import Helper.Utils, only: [get_config: 2]

alias Helper.Cache

@endpoint "https://plausible.io"
@realtime_visitors_query "/api/v1/stats/realtime/visitors"
@timeout_limit 4000

@site_id "coderplanets.com"
# @token get_config(:plausible, :token)

@cache_pool :online_status

plug(Tesla.Middleware.BaseUrl, @endpoint)
# plug(Tesla.Middleware.Headers, [{"Authorization", "Bearer #{@token}"}])
plug(Tesla.Middleware.Retry, delay: 200, max_retries: 2)
plug(Tesla.Middleware.Timeout, timeout: @timeout_limit)
plug(Tesla.Middleware.JSON)

defp get_token(), do: get_config(:plausible, :token)

def realtime_visitors() do
query = [site_id: @site_id]
path = "#{@realtime_visitors_query}"
# NOTICE: DO NOT use Tesla.get, otherwise the middleware will not woking
# see https://github.com/teamon/tesla/issues/88
# with true <- config_env() !== :test do
with {:ok, %{body: body}} <-
get(path, query: query, headers: [{"Authorization", "Bearer #{get_token()}"}]) do
case is_number(body) do
true ->
Cache.put(@cache_pool, :realtime_visitors, body)
{:ok, Enum.max([body, 1])}

false ->
{:ok, 1}
end
else
_ ->
Cache.put(@cache_pool, :realtime_visitors, 1)
{:ok, 1}
end
end
end
30 changes: 15 additions & 15 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,39 +57,39 @@ defmodule GroupherServer.Mixfile do
{:phoenix, "~> 1.6.16"},
{:phoenix_pubsub, "~> 2.0"},
{:phoenix_html, "~> 2.14.3"},
{:ecto_sql, "~> 3.9.2"},
{:ecto_sql, "~> 3.10.1"},
{:phoenix_ecto, "~> 4.4.0"},
{:postgrex, "~> 0.16.5"},
{:gettext, "~> 0.18.0"},
{:plug_cowboy, "~> 2.6.0"},
{:plug, "~> 1.14.0"},
{:postgrex, "~> 0.17.3"},
# for i18n usage
{:gettext, "~> 0.23.1"},
{:plug_cowboy, "~> 2.6.1"},
{:plug, "~> 1.14.2"},
# GraphQl tool
{:absinthe, "~> 1.6.2"},
{:absinthe, "~> 1.7.4"},
# Plug support for Absinthe
{:absinthe_plug, "~> 1.5.4"},
{:absinthe_plug, "~> 1.5.8"},
# Password hashing lib
{:comeonin, "~> 5.3.2"},
# CORS
{:corsica, "~> 1.1.2"},
{:tesla, "~> 1.4"},
{:corsica, "~> 2.1.2"},
{:tesla, "~> 1.7.0"},
# optional, but recommended adapter
{:hackney, "~> 1.8"},
# only used for tesla's JSON-encoder
{:poison, "~> 3.1"},
{:poison, "~> 4.0.1"},
# for fake data in test env
{:faker, "~> 0.17.0"},
{:scrivener_ecto, "~> 2.7.0"},
# enhanced cursor based pagination
{:quarto, "~> 1.1.5"},
{:guardian, "~> 2.3.1"},
{:timex, "~> 3.7.5"},
{:dataloader, "~> 1.0.7"},
{:guardian, "~> 2.3.2"},
{:timex, "~> 3.7.11"},
{:dataloader, "~> 2.0.0"},
{:mix_test_watch, "~> 1.0.2", only: :dev, runtime: false},
{:ex_unit_notifier, "~> 1.0", only: :test},
{:apollo_tracing, "~> 0.4.3"},
{:pre_commit, "~> 0.3.4"},
{:inch_ex, "~> 2.0", only: [:dev, :test]},
{:short_maps, "~> 0.1.1"},
{:short_maps, "~> 0.1.2"},
{:jason, "~> 1.1.1"},
{:credo, "~> 1.5.5", only: [:dev, :test], runtime: false},
{:dialyxir, "~> 1.1.0", only: [:dev, :mock], runtime: false},
Expand Down
Loading
Loading