mirror of
https://github.com/binwiederhier/ntfy.git
synced 2026-01-19 00:27:25 +01:00
Compare commits
12 Commits
http-clipb
...
require-lo
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50f3563477 | ||
|
|
e08f3670d1 | ||
|
|
4f6f45a9c0 | ||
|
|
3de04b27ab | ||
|
|
ec1f97b726 | ||
|
|
569d89e8f8 | ||
|
|
f2f146e39b | ||
|
|
18d08298cc | ||
|
|
1916376f8d | ||
|
|
f6bd0a8d51 | ||
|
|
f72f0d800f | ||
|
|
03aeb707f2 |
@@ -21,7 +21,7 @@
|
||||
# default-command:
|
||||
|
||||
# Subscriptions to topics and their actions. This option is primarily used by the systemd service,
|
||||
# or if you cann "ntfy subscribe --from-config" directly.
|
||||
# or if you can "ntfy subscribe --from-config" directly.
|
||||
#
|
||||
# Example:
|
||||
# subscribe:
|
||||
|
||||
@@ -63,6 +63,7 @@ var flagsServe = append(
|
||||
altsrc.NewBoolFlag(&cli.BoolFlag{Name: "enable-signup", Aliases: []string{"enable_signup"}, EnvVars: []string{"NTFY_ENABLE_SIGNUP"}, Value: false, Usage: "allows users to sign up via the web app, or API"}),
|
||||
altsrc.NewBoolFlag(&cli.BoolFlag{Name: "enable-login", Aliases: []string{"enable_login"}, EnvVars: []string{"NTFY_ENABLE_LOGIN"}, Value: false, Usage: "allows users to log in via the web app, or API"}),
|
||||
altsrc.NewBoolFlag(&cli.BoolFlag{Name: "enable-reservations", Aliases: []string{"enable_reservations"}, EnvVars: []string{"NTFY_ENABLE_RESERVATIONS"}, Value: false, Usage: "allows users to reserve topics (if their tier allows it)"}),
|
||||
altsrc.NewBoolFlag(&cli.BoolFlag{Name: "require-login", Aliases: []string{"require_login"}, EnvVars: []string{"NTFY_REQUIRE_LOGIN"}, Value: false, Usage: "all actions via the web app requires a login"}),
|
||||
altsrc.NewStringFlag(&cli.StringFlag{Name: "upstream-base-url", Aliases: []string{"upstream_base_url"}, EnvVars: []string{"NTFY_UPSTREAM_BASE_URL"}, Value: "", Usage: "forward poll request to an upstream server, this is needed for iOS push notifications for self-hosted servers"}),
|
||||
altsrc.NewStringFlag(&cli.StringFlag{Name: "upstream-access-token", Aliases: []string{"upstream_access_token"}, EnvVars: []string{"NTFY_UPSTREAM_ACCESS_TOKEN"}, Value: "", Usage: "access token to use for the upstream server; needed only if upstream rate limits are exceeded or upstream server requires auth"}),
|
||||
altsrc.NewStringFlag(&cli.StringFlag{Name: "smtp-sender-addr", Aliases: []string{"smtp_sender_addr"}, EnvVars: []string{"NTFY_SMTP_SENDER_ADDR"}, Usage: "SMTP server address (host:port) for outgoing emails"}),
|
||||
@@ -171,6 +172,7 @@ func execServe(c *cli.Context) error {
|
||||
webRoot := c.String("web-root")
|
||||
enableSignup := c.Bool("enable-signup")
|
||||
enableLogin := c.Bool("enable-login")
|
||||
requireLogin := c.Bool("require-login")
|
||||
enableReservations := c.Bool("enable-reservations")
|
||||
upstreamBaseURL := c.String("upstream-base-url")
|
||||
upstreamAccessToken := c.String("upstream-access-token")
|
||||
@@ -318,10 +320,12 @@ func execServe(c *cli.Context) error {
|
||||
return errors.New("if upstream-base-url is set, base-url must also be set")
|
||||
} else if upstreamBaseURL != "" && baseURL != "" && baseURL == upstreamBaseURL {
|
||||
return errors.New("base-url and upstream-base-url cannot be identical, you'll likely want to set upstream-base-url to https://ntfy.sh, see https://ntfy.sh/docs/config/#ios-instant-notifications")
|
||||
} else if authFile == "" && (enableSignup || enableLogin || enableReservations || stripeSecretKey != "") {
|
||||
return errors.New("cannot set enable-signup, enable-login, enable-reserve-topics, or stripe-secret-key if auth-file is not set")
|
||||
} else if authFile == "" && (enableSignup || enableLogin || requireLogin || enableReservations || stripeSecretKey != "") {
|
||||
return errors.New("cannot set enable-signup, enable-login, require-login, enable-reserve-topics, or stripe-secret-key if auth-file is not set")
|
||||
} else if enableSignup && !enableLogin {
|
||||
return errors.New("cannot set enable-signup without also setting enable-login")
|
||||
} else if requireLogin && !enableLogin {
|
||||
return errors.New("cannot set require-login without also setting enable-login")
|
||||
} else if !payments.Available && (stripeSecretKey != "" || stripeWebhookKey != "") {
|
||||
return errors.New("cannot set stripe-secret-key or stripe-webhook-key, support for payments is not available in this build (nopayments)")
|
||||
} else if stripeSecretKey != "" && (stripeWebhookKey == "" || baseURL == "") {
|
||||
@@ -475,6 +479,7 @@ func execServe(c *cli.Context) error {
|
||||
conf.BillingContact = billingContact
|
||||
conf.EnableSignup = enableSignup
|
||||
conf.EnableLogin = enableLogin
|
||||
conf.RequireLogin = requireLogin
|
||||
conf.EnableReservations = enableReservations
|
||||
conf.EnableMetrics = enableMetrics
|
||||
conf.MetricsListenHTTP = metricsListenHTTP
|
||||
|
||||
@@ -1698,6 +1698,7 @@ variable before running the `ntfy` command (e.g. `export NTFY_LISTEN_HTTP=:80`).
|
||||
| `enable-signup` | `NTFY_ENABLE_SIGNUP` | *boolean* (`true` or `false`) | `false` | Allows users to sign up via the web app, or API |
|
||||
| `enable-login` | `NTFY_ENABLE_LOGIN` | *boolean* (`true` or `false`) | `false` | Allows users to log in via the web app, or API |
|
||||
| `enable-reservations` | `NTFY_ENABLE_RESERVATIONS` | *boolean* (`true` or `false`) | `false` | Allows users to reserve topics (if their tier allows it) |
|
||||
| `require-login` | `NTFY_REQUIRE_LOGIN` | *boolean* (`true` or `false`) | `false` | All actions via the web app require a login |
|
||||
| `stripe-secret-key` | `NTFY_STRIPE_SECRET_KEY` | *string* | - | Payments: Key used for the Stripe API communication, this enables payments |
|
||||
| `stripe-webhook-key` | `NTFY_STRIPE_WEBHOOK_KEY` | *string* | - | Payments: Key required to validate the authenticity of incoming webhooks from Stripe |
|
||||
| `billing-contact` | `NTFY_BILLING_CONTACT` | *email address* or *website* | - | Payments: Email or website displayed in Upgrade dialog as a billing contact |
|
||||
|
||||
@@ -1470,6 +1470,10 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release
|
||||
|
||||
### ntfy server v2.15.0 (UNRELEASED)
|
||||
|
||||
**Features:**
|
||||
|
||||
* Add `require-login` flag to redirect to login page if not logged in ([#1434](https://github.com/binwiederhier/ntfy/pull/1434)/[#238](https://github.com/binwiederhier/ntfy/issues/238)/[#1329](https://github.com/binwiederhier/ntfy/pull/1329), thanks to [@theatischbein](https://github.com/theatischbein) for implementing most of this)
|
||||
|
||||
**Bug fixes + maintenance:**
|
||||
|
||||
* Add mutex around message cache writes to avoid `database locked` errors ([#1397](https://github.com/binwiederhier/ntfy/pull/1397), [#1391](https://github.com/binwiederhier/ntfy/issues/1391), thanks to [@timofej673](https://github.com/timofej673))
|
||||
|
||||
@@ -162,6 +162,7 @@ type Config struct {
|
||||
BillingContact string
|
||||
EnableSignup bool // Enable creation of accounts via API and UI
|
||||
EnableLogin bool
|
||||
RequireLogin bool
|
||||
EnableReservations bool // Allow users with role "user" to own/reserve topics
|
||||
EnableMetrics bool
|
||||
AccessControlAllowOrigin string // CORS header field to restrict access from web clients
|
||||
@@ -256,6 +257,7 @@ func NewConfig() *Config {
|
||||
EnableSignup: false,
|
||||
EnableLogin: false,
|
||||
EnableReservations: false,
|
||||
RequireLogin: false,
|
||||
AccessControlAllowOrigin: "*",
|
||||
Version: "",
|
||||
WebPushPrivateKey: "",
|
||||
|
||||
@@ -9,8 +9,6 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"gopkg.in/yaml.v2"
|
||||
"heckel.io/ntfy/v2/payments"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -33,7 +31,9 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"gopkg.in/yaml.v2"
|
||||
"heckel.io/ntfy/v2/log"
|
||||
"heckel.io/ntfy/v2/payments"
|
||||
"heckel.io/ntfy/v2/user"
|
||||
"heckel.io/ntfy/v2/util"
|
||||
"heckel.io/ntfy/v2/util/sprig"
|
||||
@@ -600,6 +600,7 @@ func (s *Server) handleWebConfig(w http.ResponseWriter, _ *http.Request, _ *visi
|
||||
BaseURL: "", // Will translate to window.location.origin
|
||||
AppRoot: s.config.WebRoot,
|
||||
EnableLogin: s.config.EnableLogin,
|
||||
RequireLogin: s.config.RequireLogin,
|
||||
EnableSignup: s.config.EnableSignup,
|
||||
EnablePayments: s.config.StripeSecretKey != "",
|
||||
EnableCalls: s.config.TwilioAccount != "",
|
||||
|
||||
@@ -258,9 +258,11 @@
|
||||
#
|
||||
# - enable-signup allows users to sign up via the web app, or API
|
||||
# - enable-login allows users to log in via the web app, or API
|
||||
# - require-login redirects users to the login page if they are not logged in (disallows web app access without login)
|
||||
# - enable-reservations allows users to reserve topics (if their tier allows it)
|
||||
#
|
||||
# enable-signup: false
|
||||
# require-login: false
|
||||
# enable-login: false
|
||||
# enable-reservations: false
|
||||
|
||||
|
||||
@@ -449,6 +449,7 @@ type apiConfigResponse struct {
|
||||
BaseURL string `json:"base_url"`
|
||||
AppRoot string `json:"app_root"`
|
||||
EnableLogin bool `json:"enable_login"`
|
||||
RequireLogin bool `json:"require_login"`
|
||||
EnableSignup bool `json:"enable_signup"`
|
||||
EnablePayments bool `json:"enable_payments"`
|
||||
EnableCalls bool `json:"enable_calls"`
|
||||
|
||||
@@ -9,6 +9,7 @@ var config = {
|
||||
base_url: window.location.origin, // Change to test against a different server
|
||||
app_root: "/",
|
||||
enable_login: true,
|
||||
require_login: true,
|
||||
enable_signup: true,
|
||||
enable_payments: false,
|
||||
enable_reservations: true,
|
||||
|
||||
@@ -309,5 +309,100 @@
|
||||
"account_delete_dialog_button_cancel": "Cancelar",
|
||||
"account_upgrade_dialog_cancel_warning": "Isto irá <strong>cancelar a sua assinatura</strong>, e fazer downgrade da sua conta em {{date}}. Nessa data, tópicos reservados bem como mensagens guardadas no servidor <strong>serão eliminados</strong>.",
|
||||
"account_upgrade_dialog_proration_info": "<strong>Proporção</strong>: Quando atualizar entre planos pagos, a diferença de preço será <strong>debitada imediatamente</strong>. Quando efetuar um downgrade para um escalão inferior, o saldo disponível será usado para futuros períodos de faturação.",
|
||||
"prefs_users_description_no_sync": "Utilizadores e palavras-passe não estão sincronizados com a sua conta."
|
||||
"prefs_users_description_no_sync": "Utilizadores e palavras-passe não estão sincronizados com a sua conta.",
|
||||
"account_upgrade_dialog_reservations_warning_one": "O nível selecionado permite menos tópicos reservados do que o nível atual. Antes de alterar o seu nível, <strong>apague pelo menos uma reserva</strong>. Pode remover reservas nas <Link>Configurações</Link>.",
|
||||
"account_upgrade_dialog_reservations_warning_other": "O nível selecionado permite menos tópicos reservados do que o seu nível atual. Antes de mudar o seu nível, <strong>por favor apague ao menos {{count}} reservas</strong>. Pode remover reservas nas <Link>Configurações</Link>.",
|
||||
"account_upgrade_dialog_tier_features_reservations_one": "{{reservations}} tópico reservado",
|
||||
"account_upgrade_dialog_tier_features_reservations_other": "{{reservations}} tópicos reservados",
|
||||
"account_upgrade_dialog_tier_features_no_reservations": "Sem tópicos reservados",
|
||||
"account_upgrade_dialog_tier_features_messages_one": "{{messages}} mensagen diária",
|
||||
"account_upgrade_dialog_tier_features_messages_other": "{{messages}} mensagens diárias",
|
||||
"account_upgrade_dialog_tier_features_emails_one": "{{emails}} email diário",
|
||||
"account_upgrade_dialog_tier_features_emails_other": "{{emails}} emails diários",
|
||||
"account_upgrade_dialog_tier_features_calls_one": "{{calls}} chamadas diárias",
|
||||
"account_upgrade_dialog_tier_features_calls_other": "{{calls}} chamadas telefônicas diárias",
|
||||
"account_upgrade_dialog_tier_features_no_calls": "Nenhuma chamada",
|
||||
"account_upgrade_dialog_tier_features_attachment_file_size": "{{filesize}} por ficheiro",
|
||||
"account_upgrade_dialog_tier_features_attachment_total_size": "{{totalsize}} armazenamento total",
|
||||
"account_upgrade_dialog_tier_price_per_month": "mês",
|
||||
"account_upgrade_dialog_tier_price_billed_monthly": "{{price}} por ano. Cobrado mensalmente.",
|
||||
"account_upgrade_dialog_tier_price_billed_yearly": "{{price}} cobrado anualmente. Gravar {{save}}.",
|
||||
"account_upgrade_dialog_tier_selected_label": "Selecionado",
|
||||
"account_upgrade_dialog_tier_current_label": "Atual",
|
||||
"account_upgrade_dialog_billing_contact_email": "Para questões de cobrança, <Link>entre em contacto conosco</Link> diretamente.",
|
||||
"account_upgrade_dialog_billing_contact_website": "Para perguntas sobre o faturamento, consulte o nosso <Link>website</Link>.",
|
||||
"account_upgrade_dialog_button_cancel": "Cancelar",
|
||||
"account_upgrade_dialog_button_redirect_signup": "Cadastre-se agora",
|
||||
"account_upgrade_dialog_button_pay_now": "Pague agora para assinar",
|
||||
"account_upgrade_dialog_button_cancel_subscription": "Cancelar assinatura",
|
||||
"account_upgrade_dialog_button_update_subscription": "Atualizar assinatura",
|
||||
"account_tokens_title": "Tokens de Acesso",
|
||||
"account_tokens_description": "Use tokens de acesso ao publicar e assinar por meio da API ntfy, para que não precise enviar as credenciais da sua conta. Consulte a <Link>documentação</Link> para saber mais.",
|
||||
"account_tokens_table_token_header": "Token",
|
||||
"account_tokens_table_label_header": "Rótulo",
|
||||
"account_tokens_table_last_access_header": "Último acesso",
|
||||
"account_tokens_table_expires_header": "Expira",
|
||||
"account_tokens_table_never_expires": "Nunca expira",
|
||||
"account_tokens_table_current_session": "Sessão atual do navegador",
|
||||
"account_tokens_table_copied_to_clipboard": "Token de acesso copiado",
|
||||
"account_tokens_table_cannot_delete_or_edit": "Não é possível editar ou apagar o token da sessão atual",
|
||||
"account_tokens_table_create_token_button": "Criar token de acesso",
|
||||
"account_tokens_table_last_origin_tooltip": "Do endereço IP {{ip}}, clique para pesquisar",
|
||||
"account_tokens_dialog_title_create": "Criar token de acesso",
|
||||
"account_tokens_dialog_title_edit": "Editar token de acesso",
|
||||
"account_tokens_dialog_title_delete": "Apagar token de acesso",
|
||||
"account_tokens_dialog_label": "Rótulo, por exemplo, notificações de Radarr",
|
||||
"account_tokens_dialog_button_create": "Criar token",
|
||||
"account_tokens_dialog_button_update": "Atualizar token",
|
||||
"account_tokens_dialog_button_cancel": "Cancelar",
|
||||
"account_tokens_dialog_expires_label": "O token de acesso expira em",
|
||||
"account_tokens_dialog_expires_unchanged": "Deixar a data de validade inalterada",
|
||||
"account_tokens_dialog_expires_x_hours": "O token expira em {{hours}} horas",
|
||||
"account_tokens_dialog_expires_x_days": "O token expira em {{days}} dias",
|
||||
"account_tokens_dialog_expires_never": "O token nunca expira",
|
||||
"account_tokens_delete_dialog_title": "Apagar token de acesso",
|
||||
"account_tokens_delete_dialog_description": "Antes de apagar um token de acesso, certifique-se de que nenhuma aplicação ou script esteja usando-lo ativamente. <strong>Esta ação não pode ser desfeita</strong>.",
|
||||
"account_tokens_delete_dialog_submit_button": "Apagar token permanentemente",
|
||||
"prefs_notifications_web_push_title": "Notificações em segundo plano",
|
||||
"prefs_notifications_web_push_enabled_description": "As notificações são recebidas mesmo quando a aplicação Web não está em execução (via Web Push)",
|
||||
"prefs_notifications_web_push_disabled_description": "As notificações são recebidas quando a aplicação Web está em execução (via WebSocket)",
|
||||
"prefs_notifications_web_push_enabled": "Ativado para {{server}}",
|
||||
"prefs_notifications_web_push_disabled": "Desativado",
|
||||
"prefs_users_table_cannot_delete_or_edit": "Não é possível apagar ou editar o utilizador conectado",
|
||||
"prefs_appearance_theme_title": "Tema",
|
||||
"prefs_appearance_theme_system": "Sistema (padrão)",
|
||||
"prefs_appearance_theme_dark": "Modo escuro",
|
||||
"prefs_appearance_theme_light": "Modo claro",
|
||||
"prefs_reservations_title": "Tópicos reservados",
|
||||
"prefs_reservations_description": "Pode reservar nomes de tópicos para uso pessoal aqui. A reserva de um tópico lhe dá propriedade sobre ele e permite que defina permissões de acesso para outros utilizadores sobre o tópico.",
|
||||
"prefs_reservations_limit_reached": "Atingiu o seu limite de tópicos reservados.",
|
||||
"prefs_reservations_add_button": "Adicionar tópico reservado",
|
||||
"prefs_reservations_edit_button": "Editar o acesso ao tópico",
|
||||
"prefs_reservations_delete_button": "Redefinir o acesso ao tópico",
|
||||
"prefs_reservations_table": "Tabela de tópicos reservados",
|
||||
"prefs_reservations_table_topic_header": "Tópico",
|
||||
"prefs_reservations_table_access_header": "Acesso",
|
||||
"prefs_reservations_table_everyone_deny_all": "Somente eu posso publicar e me inscrever",
|
||||
"prefs_reservations_table_everyone_read_only": "Posso publicar e me inscrever, todos podem se inscrever",
|
||||
"prefs_reservations_table_everyone_write_only": "Posso publicar e me inscrever, todos podem publicar",
|
||||
"prefs_reservations_table_everyone_read_write": "Todos podem publicar e se inscreverem",
|
||||
"prefs_reservations_table_not_subscribed": "Não inscrito",
|
||||
"prefs_reservations_table_click_to_subscribe": "Clique para se inscrever",
|
||||
"prefs_reservations_dialog_title_add": "Reservar tópico",
|
||||
"prefs_reservations_dialog_title_edit": "Editar tópico reservado",
|
||||
"prefs_reservations_dialog_title_delete": "Apagar reserva de tópico",
|
||||
"prefs_reservations_dialog_description": "A reserva de um tópico lhe dá propriedade sobre ele e permite definir permissões de acesso para outros utilizadores sobre o tópico.",
|
||||
"prefs_reservations_dialog_topic_label": "Tópico",
|
||||
"prefs_reservations_dialog_access_label": "Acesso",
|
||||
"reservation_delete_dialog_description": "A remoção de uma reserva abre mão da propriedade sobre o tópico e permite que outros o reservem. Pode manter ou apagar as mensagens e os anexos existentes.",
|
||||
"reservation_delete_dialog_action_keep_title": "Manter mensagens e anexos em cache",
|
||||
"reservation_delete_dialog_action_keep_description": "As mensagens e os anexos armazenados em cache no servidor ficarão visíveis publicamente para as pessoas que souberem o nome do tópico.",
|
||||
"reservation_delete_dialog_action_delete_title": "Apagar mensagens e anexos armazenados em cache",
|
||||
"reservation_delete_dialog_action_delete_description": "As mensagens e os anexos armazenados em cache serão apagados permanentemente. Esta ação não pode ser desfeita.",
|
||||
"reservation_delete_dialog_submit_button": "Apagar reserva",
|
||||
"error_boundary_button_reload_ntfy": "Recarregar ntfy",
|
||||
"web_push_subscription_expiring_title": "As notificações serão pausadas",
|
||||
"web_push_subscription_expiring_body": "Abra o ntfy para continuar recebendo notificações",
|
||||
"web_push_unknown_notification_title": "Notificação desconhecida recebida do servidor",
|
||||
"web_push_unknown_notification_body": "Talvez seja necessário atualizar o ntfy abrindo a aplicação da Web"
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ export const maybeWithBearerAuth = (headers, token) => {
|
||||
|
||||
export const withBasicAuth = (headers, username, password) => ({
|
||||
...headers,
|
||||
Authorization: basicAuth(username, password)
|
||||
Authorization: basicAuth(username, password),
|
||||
});
|
||||
|
||||
export const maybeWithAuth = (headers, user) => {
|
||||
@@ -142,7 +142,7 @@ export const getKebabCaseLangStr = (language) => language.replace(/_/g, "-");
|
||||
export const formatShortDateTime = (timestamp, language) =>
|
||||
new Intl.DateTimeFormat(getKebabCaseLangStr(language), {
|
||||
dateStyle: "short",
|
||||
timeStyle: "short"
|
||||
timeStyle: "short",
|
||||
}).format(new Date(timestamp * 1000));
|
||||
|
||||
export const formatShortDate = (timestamp, language) =>
|
||||
@@ -181,32 +181,32 @@ export const openUrl = (url) => {
|
||||
export const sounds = {
|
||||
ding: {
|
||||
file: ding,
|
||||
label: "Ding"
|
||||
label: "Ding",
|
||||
},
|
||||
juntos: {
|
||||
file: juntos,
|
||||
label: "Juntos"
|
||||
label: "Juntos",
|
||||
},
|
||||
pristine: {
|
||||
file: pristine,
|
||||
label: "Pristine"
|
||||
label: "Pristine",
|
||||
},
|
||||
dadum: {
|
||||
file: dadum,
|
||||
label: "Dadum"
|
||||
label: "Dadum",
|
||||
},
|
||||
pop: {
|
||||
file: pop,
|
||||
label: "Pop"
|
||||
label: "Pop",
|
||||
},
|
||||
"pop-swoosh": {
|
||||
file: popSwoosh,
|
||||
label: "Pop swoosh"
|
||||
label: "Pop swoosh",
|
||||
},
|
||||
beep: {
|
||||
file: beep,
|
||||
label: "Beep"
|
||||
}
|
||||
label: "Beep",
|
||||
},
|
||||
};
|
||||
|
||||
export const playSound = async (id) => {
|
||||
@@ -219,7 +219,7 @@ export const playSound = async (id) => {
|
||||
export async function* fetchLinesIterator(fileURL, headers) {
|
||||
const utf8Decoder = new TextDecoder("utf-8");
|
||||
const response = await fetch(fileURL, {
|
||||
headers
|
||||
headers,
|
||||
});
|
||||
const reader = response.body.getReader();
|
||||
let { value: chunk, done: readerDone } = await reader.read();
|
||||
@@ -228,7 +228,7 @@ export async function* fetchLinesIterator(fileURL, headers) {
|
||||
const re = /\n|\r|\r\n/gm;
|
||||
let startIndex = 0;
|
||||
|
||||
for (; ;) {
|
||||
for (;;) {
|
||||
const result = re.exec(chunk);
|
||||
if (!result) {
|
||||
if (readerDone) {
|
||||
@@ -277,17 +277,17 @@ export const urlB64ToUint8Array = (base64String) => {
|
||||
export const copyToClipboard = (text) => {
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
return navigator.clipboard.writeText(text);
|
||||
} else {
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.value = text;
|
||||
textarea.setAttribute("readonly", ""); // Avoid mobile keyboards from popping up
|
||||
textarea.style.position = "fixed"; // Avoid scroll jump
|
||||
textarea.style.left = "-9999px";
|
||||
document.body.appendChild(textarea);
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(textarea);
|
||||
return Promise.resolve();
|
||||
}
|
||||
// Fallback to the older method if clipboard API is not supported (or on HTTP)
|
||||
const textarea = document.createElement("textarea");
|
||||
textarea.value = text;
|
||||
textarea.setAttribute("readonly", ""); // Avoid mobile keyboards from popping up
|
||||
textarea.style.position = "fixed"; // Avoid scroll jump
|
||||
textarea.style.left = "-9999px";
|
||||
document.body.appendChild(textarea);
|
||||
textarea.focus();
|
||||
textarea.select();
|
||||
document.execCommand("copy");
|
||||
document.body.removeChild(textarea);
|
||||
return Promise.resolve();
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ import Account from "./Account";
|
||||
import initI18n from "../app/i18n"; // Translations!
|
||||
import prefs, { THEME } from "../app/Prefs";
|
||||
import RTLCacheProvider from "./RTLCacheProvider";
|
||||
import session from "../app/Session";
|
||||
|
||||
initI18n();
|
||||
|
||||
@@ -45,7 +46,6 @@ const darkModeEnabled = (prefersDarkMode, themePreference) => {
|
||||
const App = () => {
|
||||
const { i18n } = useTranslation();
|
||||
const languageDir = i18n.dir();
|
||||
|
||||
const [account, setAccount] = useState(null);
|
||||
const accountMemo = useMemo(() => ({ account, setAccount }), [account, setAccount]);
|
||||
const prefersDarkMode = useMediaQuery("(prefers-color-scheme: dark)");
|
||||
@@ -60,6 +60,12 @@ const App = () => {
|
||||
document.dir = languageDir;
|
||||
}, [i18n.language, languageDir]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!session.exists() && config.require_login && window.location.pathname !== routes.login) {
|
||||
window.location.href = routes.login;
|
||||
}
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Suspense fallback={<Loader />}>
|
||||
<RTLCacheProvider>
|
||||
|
||||
@@ -28,7 +28,13 @@ import { useRemark } from "react-remark";
|
||||
import styled from "@emotion/styled";
|
||||
import {
|
||||
copyToClipboard,
|
||||
formatBytes, formatShortDateTime, maybeActionErrors, openUrl, shortUrl, topicShortUrl, unmatchedTags
|
||||
formatBytes,
|
||||
formatShortDateTime,
|
||||
maybeActionErrors,
|
||||
openUrl,
|
||||
shortUrl,
|
||||
topicShortUrl,
|
||||
unmatchedTags,
|
||||
} from "../app/utils";
|
||||
import { formatMessage, formatTitle, isImage } from "../app/notificationUtils";
|
||||
import { LightboxBackdrop, Paragraph, VerticallyCenteredContainer } from "./styles";
|
||||
|
||||
Reference in New Issue
Block a user