Avatar

stu43005

Joined June 16, 2023
Likes
28
std avatar
blob
@std
Script
Blob Storage - Docs ↗ Val Town comes with blob storage built-in. It allows for storing any data, like text, JSON, or images. You can access it via std/blob . Blob storage is scoped globally to your account. If you set a blob in one val, you can retrieve it by the same key in another val. It's backed by Cloudflare R2. You may find this admin viewer helpful for viewing and editing your blobs. Get JSON import { blob } from "https://esm.town/v/std/blob"; let blobDemo = await blob.getJSON("myKey"); console.log(blobDemo); // returns `undefined` if not found Set JSON import { blob } from "https://esm.town/v/std/blob"; await blob.setJSON("myKey", { hello: "world" }); List keys import { blob } from "https://esm.town/v/std/blob"; let allKeys = await blob.list(); console.log(allKeys); const appKeys = await blob.list("app_"); console.log(appKeys); // all keys that begin with `app_` Delete by key import { blob } from "https://esm.town/v/std/blob"; await blob.delete("myKey"); Examples Counter RSS Notifications (saving the last run time) Picture: Save & Read Error Handling blob.get can throw ValTownBlobNotFoundError Any method can throw ValTownBlobError for unexpected errors. Utilities Our Blob SDK also includes some utility functions to make working with blobs easier. Copy import { blob } from "https://esm.town/v/std/blob"; await blob.copy("myKey", "myKeyCopy"); Move import { blob } from "https://esm.town/v/std/blob"; await blob.move("myKey", "myKeyNew"); Lower-level API We provide access to the lower-level getter and setters, which are useful if you are storing non-JSON or binary data, need to stream in your response or request data, or do anything else lower-level. async get(key: string) : Retrieves a blob for a given key. async set(key: string, value: string | BodyInit) : Sets the blob value for a given key. See BodyInit . Limitations Blob-stored data counts towards your total Val Town storage – 10mb on the free plan and 1gb on pro. Check our pricing page to learn more. Keys for blobs can be up to 512 characters long. 📝 Edit docs
stevekrouse avatar
refs
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
fil avatar
d3ChordDiagram
@fil
HTTP
D3 Chord diagram Example taken from the D3 Gallery , and rendered (server-side) as a static SVG served through the web end point .
std avatar
turso
@std
Script
Deprecated in favor of std/sqlite (also powered by Turso) std/turso was the initial version of our integration with Turso. It was so popular, we rebuilt it to be faster and easier to use: std/sqlite . Turso is a serverless SQLite platform designed for the edge. It runs libSQL , their open contribution fork of SQLite. Every Val Town user automatically gets their own Turso SQLite database! It's great for >100kb data (ie bigger than a val) or when you need SQL: relations, ACID transactions, etc. Storage used in Turso will count against your Val Town total storage (10mb for free users; 1gb for Pro users). Contact us if you'd need more – it should be no problem! Getting started This val uses our public key auth scheme . Generate your keypair On your publicKey click the lock icon🔒 to change the permissions to Unlisted . Fork this helper function replacing stevekrouse with your own username Try out some queries! Usage This val returns a Turso SDK's Client , which supports execute , batch , and transaction . await @me.turso().execute(`create table blobs( key text unique, value text )`) More example usage Architecture This @std.turso function is the client or SDK to @std.tursoAPI, which acts as a "proxy" to Turso. It handles authentication, creates databases, and forwards on your SQL queries. You can get lower latency (~200ms vs ~800ms), more storage, databases, CLI & API access by having your own Turso account.
stevekrouse avatar
r2
@stevekrouse
Script
r2 wrapper Save blobs without leaving Val Town! Only for Val Town Pro users to limit abuse. We get 10gb free, so as long as nobody abuses this, I won't put any strict limits on it. If you want to use more than 10gb, let me know, and we can bill you for it. All data in this bucket is public if you know it's name! This val, @stevekrouse.r2, is the "SDK" for @stevekrouse.r2Proxy . Setup This val requires you to setup public key auth, which is really just three clicks here: https://blog.val.town/public-key-auth-val-town-users-can-be-your-users [Optional] You can setup a helper function so you don't have to pass your keys every time: let blob = (key, value) => @stevekrouse.r2(key, value, @me.exportedKeys) Warning: Do not make your blob function public or unlisted. That would allow anyone to use it. Usage await @me.blob("demo", { hello: "world" }); return @me.blob("demo"); // {hello: "world"} Example usage: https://www.val.town/v/stevekrouse.r2Demo
xkonti avatar
ntfy
@xkonti
Script
Allows to publish a ntfy notification using a fluent builder configuration. Usage example import { ntfy } from "https://esm.town/v/xkonti/ntfy"; await ntfy() .toServer(Deno.env.get("ntfyServer")) .asUser(Deno.env.get("ntfyUser"), Deno.env.get("ntfyPassword")) .toTopic("testing") .withMessage("Hello there!") .withTitle("First test") .withViewAction("My website", "https://xkonti.tech") .withTags("package", "val-town") .withPriority("high") .publish(); ⚠️ For the notification to be sent it needs to be published ( publish function). Use helper Executes specified functions that can modify the notification. Can be used to streamline authentication, apply common operations, etc. import { ntfy } from "https://esm.town/v/xkonti/ntfy"; const toMyNtfyServer = (builder: ReturnType<typeof ntfy>) => { builder .toServer(Deno.env.get("ntfyServer")) .asUser(Deno.env.get("ntfyUser"), Deno.env.get("ntfyPassword")); }; await ntfy() .use(toMyNtfyServer) .toTopic('home-automation') .withMessage('You left the front door open') .publish(); You can pass it multiple functions. Functions toServer(url) - optional Specifies a server that the notification will be sent do. By default it's https://ntfy.sh . asUser(user, password) - optional Authenticates with the user and password. Please use ValTown's secrets for this. await ntfy() .asUser('user123', '12345') ... usingToken(token) - optional Authenticates using the provided token. Please use ValTown's secrets for this. await ntfy() .usingToken('some-token') ... toTopic(topic) - required Specifies which topic to publish the message to. await ntfy() .toTopic('home-automation') ... withMessage(message, markdown) - required Specifies the main message of the notification. You can also flag it as markdown by passing true as a second argument. By default markdown is false . await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') ... await ntfy() .toTopic('home-automation') .withMessage('Your garage is **flooding**!', true) ... withTitle(title) - optional Sets the title of the notification. await ntfy() .toTopic('home-automation') .withTitle('Garage') .withMessage('You left the front door open') ... withPriority(priority) - optional Sets the priority of the notification. Possible from lowest to highest priority: min , low , default , high , max await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withPriority('high') ... Alternatively you can use dedicated functions: .withMinPriority() , .withLowPriority() , .withDefaultPriority() , .withHighPriority() , .withMaxPriority() await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withHighPriority() ... withTags(...tags) - optional Sets tags of the notification. This overrides any previously existing tags. await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withTags('door', 'safety') ... withDelay(delay) - optional Sets the delay for notification delivery. Read ntfy docs for more info. await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withDelay('tomorrow, 10am') ... withViewAction(label, url, clear?) - optional Adds an action button that opens a website or app when tapped. label - Label of the action button in the notification url - URL to open when action is tapped clear - Clear notification after action button is tapped (defaults to false ) await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withViewAction('View Val', 'https://www.val.town/v/xkonti/ntfy') ... withBroadcastAction(label, intent?, extras?, clear?) - optional Adds an action button that sends an Android broadcast intent when tapped. label - Label of the action button in the notification intent - Android intent name, default is io.heckel.ntfy.USER_ACTION extras - Android intent extras. clear - Clear notification after action button is tapped (defaults to false ) await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withBroadcastAction('Selfie', 'Take picture', { 'cmd': 'pic' }) ... withHtmlAction(label, url, method?, headers?, body?, clear?) - optional Adds an action button that sends a HTTP request when tapped. label - Label of the action button in the notification url - URL to which the HTTP request will be sent method - HTTP method to use for request, default is POST headers - HTTP headers to pass in request. body - HTTP body as a string clear - Clear notification after action button is tapped (defaults to false ) await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withHtmlAction( 'Self-destruct', 'https://self.destruct/initiate', 'POST', { 'Authentication': 'Bearer 123' }, '{"countdown":60}' ) ... withClickUrl(url) - optional Makes the notification open the specified URL when clicked (tapped). withRawAttachment(filename, filedata) - optional Attached a file to the notification. Only one file can be attached. await ntfy() .toTopic('home-automation') .withMessage('You left the front door open') .withRawAttachment('todo.txt', 'Nothing!') ... withUrlAttachment(url) - optional Attaches a file that is hosted elsewhere (URL). withIcon(url) - optional Sets an icon for the notification. viaEmail(email) - optional Sends the notification via email instead. viaPhoneCall(number) - optional Sends the notification via a phone call . The number defaults to yes , which makes it use the first phone number defined on your ntfy account. withoutCache() - optional Disables the cache for the notification. Read the docs on caching for more info. withoutFirebase() - optional Disables Firebase forwarding for the notification. Read the docs on Firebase for more info. withUnifiedPush() - optional Indicates intent of using the Unified Push for the notification. Read the docs on Unified Push for more info.
vtdocs avatar
telegramWebhookEchoMessage
@vtdocs
Script
An interactive, runnable TypeScript val by vtdocs
stevekrouse avatar
verifyAPIAuth
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
stevekrouse avatar
runValAPIAuth
@stevekrouse
Script
// Make an authenticated request to another user's val
stevekrouse avatar
pollRSSFeeds2
@stevekrouse
Cron
An interactive, runnable TypeScript val by stevekrouse
stevekrouse avatar
newRSSItems
@stevekrouse
Script
An interactive, runnable TypeScript val by stevekrouse
stevekrouse avatar
pollRSSFeeds
@stevekrouse
Cron
Poll RSS feeds This val periodically polls specified RSS feeds and send the author an email with new items. It checks each feed defined in rssFeeds for new content since the last run and sends an email with the details of the new items. Usage Fork @stevekrouse/rssFeeds and update it with your desired RSS feeds; Fork this val and replace the https://esm.town/v/stevekrouse/rssFeeds import with your newly forked val; Enjoy RSS updates on your email!
Next