import {
getState,
setState,
} from "https://deno.land/x/windmill@v1.85.0/mod.ts";
/**
* **IMPORTANT:** This does not return listenings on the first run.
*
* You can read more about the Listenings History API at
* https://docs.funkwhale.audio/swagger/#/User%20activity/get_api_v1_history_listenings
*/
type Funkwhale = {
baseUrl: string;
token: string;
};
export async function main(
auth: Funkwhale,
query?: string,
scope = "all",
page_size = 10,
) {
const previousState = await getState();
const url = new URL("/api/v1/history/listenings", auth.baseUrl);
const params = { query, scope, page_size };
Object.entries(params).forEach(([key, value]) => {
value && url.searchParams.append(key, encodeURIComponent(value));
});
const response = await fetch(url, {
headers: {
Authorization: `Bearer ${auth.token}`,
},
});
const data = await response.json();
data.results.reverse();
const newListenings = [];
let latestId;
for (const listening of data.results) {
if (latestId === undefined || listening.id > latestId) {
latestId = listening.id;
}
if (
previousState?.latestId !== undefined &&
listening.id <= previousState.latestId
) {
continue;
}
newListenings.push(listening);
}
if (latestId !== undefined) {
await setState({
latestId,
});
}
return newListenings;
}
Submitted by admin 497 days ago
import { getState, setState } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
/**
* **IMPORTANT:** This does not return listenings on the first run.
*
* You can read more about the Listenings History API at
* https://docs.funkwhale.audio/swagger/#/User%20activity/get_api_v1_history_listenings
*/
type Funkwhale = {
baseUrl: string;
token: string;
};
export async function main(
auth: Funkwhale,
query?: string,
scope = "all",
page_size = 10
) {
const previousState = await getState();
const url = new URL('/api/v1/history/listenings', auth.baseUrl);
const params = { query, scope, page_size }
Object.entries(params).forEach(([key, value]) => {
value && url.searchParams.append(key, encodeURIComponent(value));
})
const response = await fetch(url, {
headers: {
"Authorization": `Bearer ${auth.token}`,
},
});
const data = await response.json();
data.results.reverse();
const newListenings = [];
let latestId;
for(const listening of data.results) {
if (latestId === undefined || listening.id > latestId) {
latestId = listening.id;
}
if (previousState?.latestId !== undefined && listening.id <= previousState.latestId) {
continue;
}
newListenings.push(listening);
}
if (latestId !== undefined) {
await setState({
latestId,
});
}
return newListenings;
}
Submitted by admin 500 days ago
import { Resource, getState, setState } from "https://deno.land/x/windmill@v1.85.0/mod.ts";
/**
* **IMPORTANT:** This does not return listenings on the first run.
*
* You can read more about the Listenings History API at
* https://docs.funkwhale.audio/swagger/#/User%20activity/get_api_v1_history_listenings
*/
export async function main(
auth: Resource<'funkwhale'>,
query?: string,
scope = "all",
page_size = 10
) {
const previousState = await getState();
const url = new URL('/api/v1/history/listenings', auth.baseUrl);
const params = { query, scope, page_size }
Object.entries(params).forEach(([key, value]) => {
value && url.searchParams.append(key, encodeURIComponent(value));
})
const response = await fetch(url, {
headers: {
"Authorization": `Bearer ${auth.token}`,
},
});
const data = await response.json();
data.results.reverse();
const newListenings = [];
let latestId;
for(const listening of data.results) {
if (latestId === undefined || listening.id > latestId) {
latestId = listening.id;
}
if (previousState?.latestId !== undefined && listening.id <= previousState.latestId) {
continue;
}
newListenings.push(listening);
}
if (latestId !== undefined) {
await setState({
latestId,
});
}
return newListenings;
}
Submitted by adam186 628 days ago
import { Resource, getState, setState } from "https://deno.land/x/windmill@v1.70.1/mod.ts";
/**
* **IMPORTANT:** This does not return listenings on the first run.
*
* You can read more about the Listenings History API at
* https://docs.funkwhale.audio/swagger/#/User%20activity/get_api_v1_history_listenings
*/
export async function main(
auth: Resource<'funkwhale'>,
query?: string,
scope = "all",
page_size = 10
) {
const previousState = await getState();
const url = new URL('/api/v1/history/listenings', auth.baseUrl);
const params = { query, scope, page_size }
Object.entries(params).forEach(([key, value]) => {
value && url.searchParams.append(key, encodeURIComponent(value));
})
const response = await fetch(url, {
headers: {
"Authorization": `Bearer ${auth.token}`,
},
});
const data = await response.json();
data.results.reverse();
const newListenings = [];
let latestId;
for(const listening of data.results) {
if (latestId === undefined || listening.id > latestId) {
latestId = listening.id;
}
if (previousState?.latestId !== undefined && listening.id <= previousState.latestId) {
continue;
}
newListenings.push(listening);
}
if (latestId !== undefined) {
await setState({
latestId,
});
}
return newListenings;
}
Submitted by adam186 663 days ago
import { Resource, getState, setState } from "https://deno.land/x/windmill@v1.55.0/mod.ts";
/**
* **IMPORTANT:** This does not return listenings on the first run.
*
* You can read more about the Listenings History API at
* https://docs.funkwhale.audio/swagger/#/User%20activity/get_api_v1_history_listenings
*/
export async function main(
auth: Resource<'funkwhale'>,
query?: string,
scope = "all",
page_size = 10
) {
const previousState = await getState();
const url = new URL('/api/v1/history/listenings', auth.baseUrl);
const params = { query, scope, page_size }
Object.entries(params).forEach(([key, value]) => {
value && url.searchParams.append(key, encodeURIComponent(value));
})
const response = await fetch(url, {
headers: {
"Authorization": `Bearer ${auth.token}`,
},
});
const data = await response.json();
data.results.reverse();
const newListenings = [];
let latestId;
for(const listening of data.results) {
if (latestId === undefined || listening.id > latestId) {
latestId = listening.id;
}
if (previousState?.latestId !== undefined && listening.id <= previousState.latestId) {
continue;
}
newListenings.push(listening);
}
if (latestId !== undefined) {
await setState({
latestId,
});
}
return newListenings;
}
Submitted by adam186 734 days ago
import * as wmill from "https://deno.land/x/windmill@v1.35.0/mod.ts"
// Watches for new listenings. Does not return listenings on the first run.
//
// At max, this will return 10 new listenings.
// If your schedule doesn't run often, you might miss some.
export async function main(baseUrl: string, token: string, query?: string, scope="all") {
const previousState = await wmill.getInternalState();
// https://docs.funkwhale.audio/swagger/#/User%20activity/get_api_v1_history_listenings
// Pagination is set to 10 so that the returned JSON object isn't to large for Windmill.
let url = `${baseUrl}/api/v1/history/listenings?page_size=10}`;
url = query ? `${url}&query=${encodeURIComponent(query)}` : url;
url = scope ? `${url}&scope=${encodeURIComponent(scope)}` : url;
const response = await fetch(url, {
headers: {
"Authorization": `Bearer ${token}`,
},
});
const data = await response.json();
data.results.reverse();
const newListenings = [];
let latestId;
for(const listening of data.results) {
if (latestId === undefined || listening.id > latestId) {
latestId = listening.id;
}
if (previousState?.latestId !== undefined && listening.id <= previousState.latestId) {
continue;
}
newListenings.push(listening);
}
if (latestId !== undefined) {
await wmill.setInternalState({
latestId,
});
}
return newListenings;
}
Submitted by jaller94 814 days ago
import * as wmill from "https://deno.land/x/windmill@v1.35.0/mod.ts"
export async function main(baseUrl: string, token: string) {
const previousState = await wmill.getInternalState();
const url = `${baseUrl}/api/v1/history/listenings?page_size=10`;
const response = await fetch(url, {
headers: {
'Authorization': `Bearer ${token}`,
},
});
const data = await response.json();
data.results.reverse();
const newListenings = [];
let latestId;
for(const listening of data.results) {
if (latestId === undefined || listening.id > latestId) {
latestId = listening.id;
}
if (previousState?.latestId !== undefined && listening.id <= previousState.latestId) {
continue;
}
newListenings.push(listening);
}
if (latestId !== undefined) {
await wmill.setInternalState({
latestId,
});
}
return newListenings;
}
Submitted by jaller94 814 days ago