SHA256
Добавлена «Отправить через» в Android
This commit is contained in:
@@ -3,7 +3,7 @@ import { t } from '../i18n/index.js';
|
||||
export const USER_PDA_SPACE = 768; // shine-solana/shine/programs/shine_users/src/settings.rs
|
||||
// Запас для предварительной проверки баланса; сеть списывает фактическую комиссию.
|
||||
export const REGISTRATION_NETWORK_RESERVE_LAMPORTS = 100_000n;
|
||||
export const UPGRADE_TEST_TOPUP_SOL = 0.032;
|
||||
export const UPGRADE_TEST_TOPUP_SOL = 0.4;
|
||||
export const LAMPORTS_PER_SOL = 1_000_000_000;
|
||||
|
||||
export function calculateRegistrationFunding({ namespaceFeeLamports, rentLamports }) {
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { readShare, deleteShare } from './share-inbox.js';
|
||||
const KEY = 'shine-share-pending-id';
|
||||
let pending = null;
|
||||
let activePath = '';
|
||||
let permittedPath = '';
|
||||
let owner = '';
|
||||
let sending = false;
|
||||
export const getPendingShare = () => pending;
|
||||
export const isShareSending = () => sending;
|
||||
export const setShareSending = value => { sending = Boolean(value); };
|
||||
export const isShareChoosing = () => Boolean(pending && activePath === '/contacts');
|
||||
export const shareForChat = chatId => pending && pending.recipient === chatId ? pending : null;
|
||||
export async function restoreShare() {
|
||||
const url = new URL(location.href);
|
||||
let id = url.searchParams.get('shine-share');
|
||||
try { id ||= sessionStorage.getItem(KEY); } catch { if (!id) return ''; }
|
||||
const error = url.searchParams.get('shine-share-error');
|
||||
if (url.searchParams.has('shine-share') || error) {
|
||||
url.searchParams.delete('shine-share'); url.searchParams.delete('shine-share-error');
|
||||
history.replaceState(history.state, '', url.pathname + url.search + url.hash);
|
||||
}
|
||||
if (error) { try { sessionStorage.removeItem(KEY); } catch {} return ['limit', 'empty', 'storage'].includes(error) ? error : 'storage'; }
|
||||
if (!id) return '';
|
||||
try {
|
||||
pending = await readShare(id);
|
||||
if (!pending) { sessionStorage.removeItem(KEY); return 'expired'; }
|
||||
try { sessionStorage.setItem(KEY, id); } catch {}
|
||||
return '';
|
||||
} catch { return 'storage'; }
|
||||
}
|
||||
export function activateShare(login) {
|
||||
if (!pending || activePath) return false;
|
||||
owner = String(login || '');
|
||||
activePath = '/contacts';
|
||||
permittedPath = '/contacts';
|
||||
return true;
|
||||
}
|
||||
export function chooseShareRecipient(chatId, path) {
|
||||
if (!isShareChoosing()) return;
|
||||
pending.recipient = chatId;
|
||||
permittedPath = path;
|
||||
}
|
||||
export function finishShare() {
|
||||
const id = pending?.id;
|
||||
pending = null; activePath = ''; permittedPath = ''; owner = ''; sending = false;
|
||||
try { sessionStorage.removeItem(KEY); } catch {}
|
||||
if (id) void deleteShare(id).catch(() => {});
|
||||
}
|
||||
export function checkShareOwner(login) {
|
||||
if (owner && owner !== String(login || '')) finishShare();
|
||||
}
|
||||
// All SPA navigation, including browser Back, goes through the same cancellation rule.
|
||||
export function allowShareNavigation(path) {
|
||||
if (!pending || !activePath || path === activePath) return true;
|
||||
if (path === permittedPath && !sending) { activePath = path; permittedPath = ''; return true; }
|
||||
if (sending) return false;
|
||||
if (!window.confirm(t('remaining.share.cancel_confirm'))) return false;
|
||||
finishShare();
|
||||
return true;
|
||||
}
|
||||
export function restoreSharePath() {
|
||||
if (activePath) history.pushState({ shineFrom: '/messages' }, '', activePath);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
// Shared by the service worker and the window. No content is sent over the network.
|
||||
const DB = 'shine-share-inbox-v1';
|
||||
const STORE = 'items';
|
||||
const TTL = 24 * 60 * 60 * 1000;
|
||||
export const MAX_SHARE_FILES = 10;
|
||||
export const MAX_SHARE_BYTES = 500 * 1024 * 1024;
|
||||
export function shareText({ title = '', text = '', url = '' } = {}) {
|
||||
const body = String(text).trim();
|
||||
const link = String(url).trim();
|
||||
const heading = String(title).trim();
|
||||
const result = [body, link && !body.includes(link) ? link : ''].filter(Boolean).join('\n');
|
||||
return [heading && !result.includes(heading) ? heading : '', result].filter(Boolean).join('\n');
|
||||
}
|
||||
function openDb() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = indexedDB.open(DB, 1);
|
||||
request.onupgradeneeded = () => request.result.createObjectStore(STORE, { keyPath: 'id' });
|
||||
request.onsuccess = () => resolve(request.result);
|
||||
request.onerror = () => reject(request.error);
|
||||
});
|
||||
}
|
||||
async function transaction(mode, action) {
|
||||
const db = await openDb();
|
||||
try {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const tx = db.transaction(STORE, mode);
|
||||
let result;
|
||||
tx.oncomplete = () => resolve(result);
|
||||
tx.onabort = tx.onerror = () => reject(tx.error || new Error('share storage failed'));
|
||||
action(tx.objectStore(STORE), value => { result = value; });
|
||||
});
|
||||
} finally { db.close(); }
|
||||
}
|
||||
export function pruneShares(now = Date.now()) {
|
||||
return transaction('readwrite', store => {
|
||||
const cursor = store.openCursor();
|
||||
cursor.onsuccess = () => {
|
||||
const row = cursor.result;
|
||||
if (!row) return;
|
||||
if (row.value.createdAt < now - TTL) row.delete();
|
||||
row.continue();
|
||||
};
|
||||
});
|
||||
}
|
||||
export async function saveShare(form) {
|
||||
const files = form.getAll('files').filter(file => typeof file !== 'string' && (file.name || file.size));
|
||||
if (files.length > MAX_SHARE_FILES || files.reduce((total, file) => total + file.size, 0) > MAX_SHARE_BYTES) throw new Error('limit');
|
||||
const text = shareText({ title: form.get('title') || '', text: form.get('text') || '', url: form.get('url') || '' });
|
||||
if (!text && !files.length) throw new Error('empty');
|
||||
const id = crypto.randomUUID();
|
||||
await pruneShares();
|
||||
await transaction('readwrite', store => store.put({ id, text, files, createdAt: Date.now() }));
|
||||
return id;
|
||||
}
|
||||
export async function readShare(id) {
|
||||
await pruneShares();
|
||||
return transaction('readonly', (store, set) => {
|
||||
const req = store.get(id);
|
||||
req.onsuccess = () => set(req.result || null);
|
||||
});
|
||||
}
|
||||
export const deleteShare = id => transaction('readwrite', store => store.delete(id));
|
||||
Reference in New Issue
Block a user