api.storage

device()

api.storage.device({ deviceId, name, userAgent }) → Promise<ConnectedStorage>

Registra un telefono o un tablet come un storage. Chiamat dal tuo server, perché il telefono non detiene mai la chiave.

POST /api/storage/devicefreesame deviceId, same storage
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Un computer registra se: il SDK corre là, scambia la chiave, e la macchina devenia un storage. Un telefono non può — il SDK non è nel e non deve ser, perché la chiave sarebbe. Quindi la pagina envia un identificator al servèrver, e il servèrvèr l'aclama.

Parâmetros

deviceIdstringobrigatório

Un identificator al azar la pagina mantiene. Manca → il SDK lança.

namestring

Il nome display. Derivè del agente utente quando ausente.

userAgentstring

Agent d'usuari del telefono, usat per quel nome.

Il medès divizimentId è il medès stoccatè

L'invocare di nuovo con un identificatore già visto restitue il stoccaggio existente in lugar de fare un altro. Così la pagina puèt inchinar a ogni carica senza cumulare registrazioni — e due chiamate simultanee ancora producen uno.

// In the page: an identifier that survives reloads
let deviceId = localStorage.getItem("device");
if (!deviceId) {
  deviceId = `dev_${crypto.randomUUID()}`;
  localStorage.setItem("device", deviceId);
}

// On your server, where the key is
export async function registerPhone(deviceId, userAgent) {
  const phone = await api.storage.device({ deviceId, userAgent });
  return phone.id;
}
# In the page (JavaScript): an identifier that survives reloads
#   localStorage.getItem("device") || `dev_${crypto.randomUUID()}`

# On your Python server, where the key is
def register_phone(device_id, user_agent):
    phone = api.storage.device(device_id=device_id, user_agent=user_agent)
    return phone.id
Generare l'identificatore, mai derivar

Un valore costruito a partir del agente utente, l'ecran o un cont è lo stesso per molte persone — e chi lo envia ottiene que storage. Random, mantenut in browser, è lo che lo rende un dispositivo.

Retorno

phone.id;
phone.type;       // "phone"
phone.provider;   // "browser"
phone.deviceId;   // the identifier you passed
phone.id
phone.type       # "phone"
phone.provider   # "browser"

I suoi files non sono a conta

Un telefono mantiene i propri files, in suo browser

Salvar a lui a través del server è negat con storage_is_local. Lectura e scrivi-le avviene in la pagina, che è onde sono — il server releve la richiesta e la pagina risponde.

E questo rende un telefono un luogo sensat per un agente per lavorare: nulla è caricat per lettura. i pods de limas.

appName separa due apps su un telefono

Un storage è identificat dal conto, il dispositivo e il appName il client è stato costruito con. Due apps in un telefono sono due storages — che è generalmente quello che si desidera, dal momento que i loro files non hanno nulla a che fare l'un cun l'altro.

const api = new IaGenify({ apiKey, appName: "field-notes" });
await api.storage.device({ deviceId });   // this app's storage on this phone
api = IaGenify(api_key=api_key, app_name="field-notes")
api.storage.device(device_id=device_id)   # this app's storage on this phone

Erros

CódigoStatusQuando
— (erro lançado localmente)—Nessun dispositivo ha superat.
non autorizzato401Non sessione o chiave valida — la chiamata è del tuo server, non del telefono.