Last active
June 2, 2024 23:16
-
-
Save circus2271/e5a2d721434745da1a00aa2107b776d3 to your computer and use it in GitHub Desktop.
sphere-desktop-app typescript demo example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Cover = { | |
// blobCover: Blob, | |
blobCover: string, // simplify it to string by now | |
httpsCoverUrl?: string | |
} | |
// } | null | |
interface Track { | |
// filename: | |
duration: number, | |
filename: string, | |
cover?: Cover, | |
// getTrackHttpsUrl(): any, // probably use Uploader class | |
} | |
class Playlist { | |
private tracks: Track[] = [] | |
addTracks(tracks: Track[]) { | |
this.tracks.push(...tracks) | |
} | |
parseMetaData() { | |
} | |
getTracksHttpsUrls() { | |
} | |
// parseCovers() { | |
// } | |
} | |
// const airtableApiEndpoint = 'https:/v0.airtable.com' | |
const BASE_ID = 'fake id' | |
const TABLE_ID = 'fake id' | |
const airtableUrl = `https://api.airtable.com/v0/${BASE_ID}/${TABLE_ID}` | |
class Uploader { | |
async uploadTracksToDigitalOcean(tracks: Track[]) { | |
const response = await fetch(airtableUrl, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify(tracks) | |
}) | |
if (response.ok) { | |
console.log('files are uploaded') | |
} | |
} | |
async uploadCoversToDigitalOcean(tracks: Track[]) { | |
// get cover blob and upload it to digital ocean | |
// get url of uploaded cover | |
for await (let track of tracks+) { | |
const response = await fetch('https://digitalocean.com/test-url', { | |
method: 'POST', | |
headers: { | |
// 'Content-Type': 'application/json', | |
'Content-Type': 'application/octet-stream', | |
body: track.cover.blobCover | |
} | |
}) | |
if (response.ok) { | |
track.cover.httpsCoverUrl = response.text//uploadedImageUrl | |
} | |
} | |
} | |
uploadPlaylistToAirtable() { | |
// split all tracks for chunks by 10 to bypass airtable's api limit | |
// simplify it by now | |
} | |
} | |
const tracks: Track[] = [ | |
{ | |
duration: 227, | |
filename: 'track1.mp3', | |
}, | |
{ | |
duration: 221, | |
filename: 'track2.mp3', | |
cover: { | |
blobCover: 'fdsfsdf' | |
} | |
}, | |
{ | |
duration: 225, | |
filename: 'track3.mp3', | |
cover: undefined | |
}, | |
{ | |
duration: 231, | |
filename: 'track4.mp3', | |
cover: { | |
blobCover: 'fdfsdf fake blob data' | |
} | |
}, | |
] | |
// const log = (name: string) => { | |
// console.log(name) | |
// } | |
// log('blabla') | |
// class Logger { | |
// log(name: string) { | |
// console.log(name) | |
// } | |
// } | |
// const logger = new Logger() | |
// logger.log('jack') | |
// class Dog { | |
// logger = new Logger() | |
// bark() { | |
// this.logger.log('bark') | |
// // this.logger.dog('bark') | |
// } | |
// } | |
// const dog = new Dog() | |
// dog.bark() | |
// // console.log(logger.dark) | |
// interface Reader { | |
// read: () => void; | |
// } | |
// class Human implements Reader { | |
// bookShelf?: BookShelf; | |
// constructor(bookShelf: BookShelf) { | |
// this.bookShelf = bookShelf | |
// } | |
// read() { | |
// console.log('hmmm') | |
// } | |
// hasBooks(): boolean { | |
// if (this.bookShelf) { | |
// return this.bookShelf.books.length > 0 | |
// } | |
// return false | |
// } | |
// } | |
// class BookShelf { | |
// constructor(private _books: Book[]) {} | |
// get books(): Book[] { | |
// return this._books | |
// } | |
// } | |
// interface Book { | |
// name: string; | |
// // title: string; | |
// author?: string; | |
// publisher?: string; | |
// } | |
// const jacksBooks: Book[] = [ | |
// { | |
// name: 'Bhagavad Gita' | |
// } | |
// ] | |
// const jacksBookShelf = new BookShelf(jacksBooks) | |
// const jack = new Human(jacksBookShelf) | |
// console.log('jack has books: ', jack.hasBooks()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment