Add a per-user OpenRouter usage integration that reads the management key and displays a single spend total next to the Bitcoin ticker. The total is configurable to Today, This week or This month, defaulting to Today. Analytics queries are widened to the previous UTC hour boundary and then filtered locally so buckets in non-whole-hour timezones are not clipped.
106 lines
3.1 KiB
Plaintext
106 lines
3.1 KiB
Plaintext
import Component from '@glimmer/component';
|
|
import { action } from '@ember/object';
|
|
import { on } from '@ember/modifier';
|
|
import { tracked } from '@glimmer/tracking';
|
|
import setStyle from '../../../modifiers/set-style';
|
|
import { safeColor } from '../../../utils/safe-color';
|
|
|
|
// Renders an integration's avatar from the most specific source available:
|
|
// a resolved site icon, then a bundled image icon, then the brand color and
|
|
// glyph from the registry.
|
|
export default class SettingsIntegrationsAvatar extends Component {
|
|
@tracked imgFailed = false;
|
|
|
|
get integration() {
|
|
return this.args.integration;
|
|
}
|
|
|
|
get siteIcon() {
|
|
return this.integration?.icon;
|
|
}
|
|
|
|
// A cached icon whose bytes aren't a decodable image fails silently in the
|
|
// browser, so ignore it and fall through to the next avatar source.
|
|
get hasSiteIcon() {
|
|
return Boolean(this.siteIcon) && !this.imgFailed;
|
|
}
|
|
|
|
@action
|
|
handleImageError() {
|
|
this.imgFailed = true;
|
|
}
|
|
|
|
get imageClass() {
|
|
return this.siteIcon?.maskable
|
|
? 'size-full object-cover'
|
|
: 'size-7 rounded-md object-contain';
|
|
}
|
|
|
|
get themeColor() {
|
|
return safeColor(this.siteIcon?.themeColor);
|
|
}
|
|
|
|
// Bundled icons are assumed to be full-bleed square canvases, but some (e.g.
|
|
// OpenRouter's glyph) have no padding of their own, so they must be inset
|
|
// instead of being cropped to the edges.
|
|
get iconUrlClass() {
|
|
return this.integration?.iconInset
|
|
? 'size-7 rounded-md object-contain'
|
|
: 'size-full object-cover';
|
|
}
|
|
|
|
get iconUrlThemeColor() {
|
|
return safeColor(this.integration?.themeColor);
|
|
}
|
|
|
|
<template>
|
|
{{#if this.hasSiteIcon}}
|
|
<span
|
|
class="icon-edge icon-edge-no-highlight flex size-10 flex-none items-center justify-center overflow-hidden rounded-lg bg-gray-100"
|
|
{{setStyle "background-color" this.themeColor}}
|
|
>
|
|
<img
|
|
src={{this.siteIcon.dataUrl}}
|
|
alt=""
|
|
aria-hidden="true"
|
|
class={{this.imageClass}}
|
|
{{on "error" this.handleImageError}}
|
|
/>
|
|
</span>
|
|
{{else if @integration.iconUrl}}
|
|
<span
|
|
class="icon-edge icon-edge-no-highlight flex size-10 flex-none items-center justify-center overflow-hidden rounded-lg"
|
|
{{setStyle "background-color" this.iconUrlThemeColor}}
|
|
>
|
|
<img
|
|
src={{@integration.iconUrl}}
|
|
alt=""
|
|
aria-hidden="true"
|
|
class={{this.iconUrlClass}}
|
|
/>
|
|
</span>
|
|
{{else}}
|
|
<span
|
|
class="icon-edge icon-edge-no-highlight flex size-10 flex-none items-center justify-center rounded-lg
|
|
{{@integration.colorClass}}"
|
|
>
|
|
<svg
|
|
viewBox="0 0 24 24"
|
|
fill={{if @integration.iconFill "currentColor" "none"}}
|
|
stroke={{if @integration.iconFill "none" "currentColor"}}
|
|
stroke-width="1.5"
|
|
data-slot="icon"
|
|
class="size-6 text-white"
|
|
>
|
|
<path
|
|
d={{@integration.iconPath}}
|
|
transform={{@integration.iconTransform}}
|
|
stroke-linecap="round"
|
|
stroke-linejoin="round"
|
|
/>
|
|
</svg>
|
|
</span>
|
|
{{/if}}
|
|
</template>
|
|
}
|