Before using these APIs please note that these are only available in v2.6.5, they will be removed in v3.
Get user IP info:
utils.getIp(refresh?: boolean): Promise<IpResult>
Use the above method of utils object to get the user ip information. The interface IpResult
is as shown:
interface Location {
cca2: string;
city: string;
iata: string;
lat: number;
lon: number;
region: string;
}
interface IpResult {
colo: string;
country?: string;
fl: string;
gateway: "off" | "on";
http: string;
ip: string;
loc: string;
location?: Location;
rbi: "off" | "on";
sliver: string;
sni: string;
timestamp: number;
tls: string;
userAgent: string;
visitScheme: string;
warp: "off" | "on";
}
Example:
utils.getIp().then((result) => {
console.log("The IP is", result.ip);
});
Multithreading using Web Worker
You can use utils.Worker constructor to create a new worker thread.
Example:const worker = new utils.Worker((self, register) => {
register((ctx) => {
return {
hello: ()=> `[from:worker]: Hello! ${ctx.message}`
}
});
}, {
context: { message: "My message" },
name: "my-worker"
});
worker.call("hello").then(result => {
console.log(result);
});
Formatting Blogger image url
utils.formatImage(bloggerImageUrl: string, options?: Options): string
You can create a new image url from existing blogger image url by modifying some of its parameters. Available options are:
interface Options {
width?: number;
height?: number;
size?: number;
ratio?: number;
forceScaling?: boolean;
flipHorizontally?: boolean;
flipVertically?: boolean;
rotate?: number;
symbol?: number;
download?: boolean;
format?: "png" | "jpg" | "webp";
cache?: number;
}
Example:
const bloggerImageUrl = "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmxL-hkIX19cdlV93xhQnaZSwqU6Jmeq7JK9P7c_FbGFfemeaMVZnC3Ow4WZbc8kMlhxGjLSR2AhN9gsxfhtkPovJJ7zUDBILREULXuvNt2aFMcUAtKbN38kPngpTfHMLwmGuGZb7zK8vaX24LRXDdXus632s2zJp7mNqqzeIar5h8E_6grv8j0T_Y4g/w600-h300/Plus_UI_Typography.webp";
const modifiedImageUrl = utils.formatImage(bloggerImageUrl, {
format: "webp"
});
console.log(modifiedImageUrl);
There are more but they are not documented yet!
Post a Comment