Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2] Service to load data from different sources #641

Draft
wants to merge 5 commits into
base: v2
Choose a base branch
from
Draft

Conversation

MacFJA
Copy link
Collaborator

@MacFJA MacFJA commented Jul 5, 2024

🎯 Changes

This PR add "service" to load data from sources (internal and external).

Implemented source:

  • Guild.host 1
  • Guild.host event
  • NPM
  • Github (indirect - used by NPM source)
  • Youtube
  • Vimeo
  • Stats (internal source) 2
  • Article (internal source) 2

Usage

Server side

The input data is minimal: the type of data and an identifier.

Each source will be interrogated if it can handle the data

await collectorService.getAllInformation([
	{ type: 'package', identifier: '@sveltejs/kit' },
	{ type: 'video', identifier: 'xCeYmdukOKI' },
])
// This will return 2 objects with an known structure

Note

CollectorService is a service that aggregate all main service

All services will be asked if they can handle a package, that can be found with an identifier (so Youtube service will respond immediately that it can't and package)

Tip

All methods that request external resource or take time to compute can be cached with the addition of a simple decorator (@Memorize(cacheStorage)) to reduce lantency

Render side

To display a data from the services, there are 5 components:

All components are design to accept the same parameter as the result of the services, so using them is simple: +page.svelte

	{#if item.type === 'package'}
		<PackageCard
			{...item}
			title={item.name}
			time={item.lastUpdate}
			tags={item.keywords.map((i) => ({ id: i, name: i }))}
		/>
	{:else if item.type === 'video'}
		<VideoCard
			{...item}
			title={item.name}
			time={item.lastUpdate}
			tags={item.keywords.map((i) => ({ id: i, name: i }))}
		/>
	{:else if item.type === 'recipe'}
		<RecipeCard
			{...item}
			title={item.name}
			time={item.lastUpdate}
			tags={item.keywords.map((i) => ({ id: i, name: i }))}
		/>
	{:else if item.type === 'guild'}
		<GuildCard {...item} title={item.name} time={item.lastUpdate} tags={[]} />
	{:else if item.type === 'guild-event'}
		<GuildEventCard {...item} title={item.name} />
	{/if}

Footnotes

  1. There is no public API, the probability that the current code won't work in a near future is pretty high 😞

  2. Need to be connected to the database 2

Copy link

vercel bot commented Jul 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
sveltesociety-dev ❌ Failed (Inspect) Jul 8, 2024 5:14pm
sveltesociety-dev-preview ❌ Failed (Inspect) Jul 8, 2024 5:14pm
sveltesociety-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 8, 2024 5:14pm

Copy link

cloudflare-workers-and-pages bot commented Jul 5, 2024

Deploying sveltesociety with  Cloudflare Pages  Cloudflare Pages

Latest commit: a92128c
Status:🚫  Build failed.

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants