-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add personalized following k3l algo
- Loading branch information
bigint
committed
Aug 11, 2023
1 parent
f238b4c
commit db12a09
Showing
13 changed files
with
81 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |
This file contains 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
This file contains 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
25 changes: 25 additions & 0 deletions
25
packages/workers/feeds/src/providers/k3l/algorithms/k3lGlobalFeed.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import randomizeIds from '../../../helpers/randomizeIds'; | ||
|
||
const k3lGlobalFeed = async ( | ||
strategy: string, | ||
limit: number, | ||
offset: number | ||
) => { | ||
try { | ||
const response = await fetch( | ||
`https://lens-api.k3l.io/feed/${strategy}?limit=${limit}&offset=${offset}`, | ||
{ headers: { 'User-Agent': 'Lenster' } } | ||
); | ||
const json: { | ||
postId: string; | ||
}[] = await response.json(); | ||
const ids = json.map((item: any) => item.postId); | ||
|
||
return randomizeIds(ids); | ||
} catch (error) { | ||
console.log(error); | ||
return []; | ||
} | ||
}; | ||
|
||
export default k3lGlobalFeed; |
26 changes: 26 additions & 0 deletions
26
packages/workers/feeds/src/providers/k3l/algorithms/k3lPersonalFeed.ts
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import randomizeIds from '../../../helpers/randomizeIds'; | ||
|
||
const k3lPersonalFeed = async ( | ||
strategy: string, | ||
profile: string, | ||
limit: number, | ||
offset: number | ||
) => { | ||
try { | ||
const response = await fetch( | ||
`https://lens-api.k3l.io/feed/personal/${profile}/${strategy}?limit=${limit}&offset=${offset}`, | ||
{ headers: { 'User-Agent': 'Lenster' } } | ||
); | ||
const json: { | ||
postId: string; | ||
}[] = await response.json(); | ||
const ids = json.map((item: any) => item.postId); | ||
|
||
return randomizeIds(ids); | ||
} catch (error) { | ||
console.log(error); | ||
return []; | ||
} | ||
}; | ||
|
||
export default k3lPersonalFeed; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,17 @@ | ||
import randomizeIds from '../../helpers/randomizeIds'; | ||
import k3lGlobalFeed from './algorithms/k3lGlobalFeed'; | ||
import k3lPersonalFeed from './algorithms/k3lPersonalFeed'; | ||
|
||
const k3lFeed = async (strategy: string, limit: number, offset: number) => { | ||
try { | ||
const response = await fetch( | ||
`https://lens-api.k3l.io/feed/${strategy}?limit=${limit}&offset=${offset}`, | ||
{ headers: { 'User-Agent': 'Lenster' } } | ||
); | ||
const json: { | ||
postId: string; | ||
}[] = await response.json(); | ||
const ids = json.map((item: any) => item.postId); | ||
|
||
return randomizeIds(ids); | ||
} catch (error) { | ||
console.log(error); | ||
return []; | ||
const k3lFeed = async ( | ||
strategy: string, | ||
profile: string, | ||
limit: number, | ||
offset: number | ||
) => { | ||
if (profile) { | ||
return await k3lPersonalFeed(strategy, profile, limit, offset); | ||
} | ||
|
||
return await k3lGlobalFeed(strategy, limit, offset); | ||
}; | ||
|
||
export default k3lFeed; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { defineConfig } from 'vitest/config'; | ||
|
||
export default defineConfig({ | ||
test: { globals: true } | ||
test: { globals: true, testTimeout: 30000 } | ||
}); |