Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ff2balex
Manage
Activity
Members
Labels
Plan
Issues
9
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Lex gaMe
ff2balex
Commits
77555e74
Commit
77555e74
authored
5 months ago
by
Prénom Nom
Browse files
Options
Downloads
Patches
Plain Diff
intégration appels api
#1
parent
d14f255f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api.js
+158
-0
158 additions, 0 deletions
api.js
token.js
+23
-0
23 additions, 0 deletions
token.js
token.txt
+1
-0
1 addition, 0 deletions
token.txt
with
182 additions
and
0 deletions
api.js
0 → 100644
+
158
−
0
View file @
77555e74
console
.
log
(
"
api.js chargé correctement
"
);
// Fonction pour récupérer les lexiques de l'utilisateur
async
function
getUserLexicons
(
authToken
)
{
const
lexiconsApiUrl
=
'
https://babalex.lezinter.net/api/user/lexicons
'
;
try
{
const
response
=
await
fetch
(
lexiconsApiUrl
,
{
method
:
'
GET
'
,
headers
:
{
Authorization
:
`Bearer
${
authToken
}
`
,
'
Content-Type
'
:
'
application/json
'
,
},
});
if
(
!
response
.
ok
)
{
throw
new
Error
(
`Erreur lors de la récupération des lexiques :
${
response
.
statusText
}
`
);
}
return
await
response
.
json
();
}
catch
(
error
)
{
console
.
error
(
'
Erreur lors de la récupération des lexiques :
'
,
error
);
throw
error
;
}
}
// Fonction pour récupérer les graphies d'un lexique donné
async
function
getLexiconEntries
(
authToken
,
idLexicon
)
{
const
entriesApiUrl
=
`https://babalex.lezinter.net/api/lexicon/entries/
${
idLexicon
}
`
;
try
{
const
response
=
await
fetch
(
entriesApiUrl
,
{
method
:
'
GET
'
,
headers
:
{
Authorization
:
`Bearer
${
authToken
}
`
,
'
Content-Type
'
:
'
application/json
'
,
},
});
if
(
!
response
.
ok
)
{
throw
new
Error
(
`Erreur lors de la récupération des graphies :
${
response
.
statusText
}
`
);
}
return
await
response
.
json
();
}
catch
(
error
)
{
console
.
error
(
'
Erreur lors de la récupération des graphies :
'
,
error
);
throw
error
;
}
}
// Fonction pour obtenir les informations d'une graphie
async
function
getWordInfo
(
authToken
,
word
)
{
const
definitionApiUrl
=
`https://babalex.lezinter.net/api/entry/search?graphy=
${
encodeURIComponent
(
word
)}
&language=fr&target_lex=3&target_lex=4`
;
try
{
const
response
=
await
fetch
(
definitionApiUrl
,
{
method
:
'
GET
'
,
headers
:
{
Authorization
:
`Bearer
${
authToken
}
`
,
'
Content-Type
'
:
'
application/json
'
,
},
});
if
(
!
response
.
ok
)
{
throw
new
Error
(
`Erreur lors de la récupération de la définition :
${
response
.
statusText
}
`
);
}
return
await
response
.
json
();
}
catch
(
error
)
{
console
.
error
(
'
Erreur lors de la récupération de la définition :
'
,
error
);
throw
error
;
}
}
// Fonction pour obtenir les définitions
function
getDefinition
(
data
)
{
// Vérifier que les données sont bien structurées
if
(
!
Array
.
isArray
(
data
))
{
console
.
warn
(
'
Les données fournies ne contiennent pas de définitions.
'
);
return
[];
}
//Liste qui contient les id / définitions
const
definitions
=
[];
// Parcours de chaque entrée pour extraire les définitions
data
.
forEach
((
entry
)
=>
{
if
(
entry
.
attributes
&&
entry
.
attributes
.
Items
)
{
entry
.
attributes
.
Items
.
forEach
((
item
)
=>
{
if
(
item
.
Sense
&&
Array
.
isArray
(
item
.
Sense
.
Definitions
))
{
item
.
Sense
.
Definitions
.
forEach
((
def
)
=>
{
definitions
.
push
({
id
:
def
.
id
||
'
ID non disponible
'
,
definition
:
def
.
Def
||
'
Définition non disponible
'
,
});
});
}
});
}
});
return
definitions
;
}
// Fonction pour obtenir une définition depuis le Wiktionnaire
async
function
getWiktionaryDefinition
(
authToken
,
word
)
{
const
wiktionaryApiUrl
=
`https://babalex.lezinter.net/api/wiktionary/search?graphy=
${
encodeURIComponent
(
word
)}
&language=fr`
;
try
{
const
response
=
await
fetch
(
wiktionaryApiUrl
,
{
method
:
'
GET
'
,
headers
:
{
Authorization
:
`Bearer
${
authToken
}
`
,
'
Content-Type
'
:
'
application/json
'
,
},
});
if
(
!
response
.
ok
)
{
throw
new
Error
(
`Erreur lors de la récupération de la définition depuis le Wiktionnaire :
${
response
.
statusText
}
`
);
}
const
data
=
await
response
.
json
();
// Extraire les définitions et leurs IDs
const
definitions
=
[];
if
(
Array
.
isArray
(
data
))
{
data
.
forEach
((
entry
)
=>
{
if
(
entry
.
science
&&
entry
.
science
.
senses
)
{
for
(
const
[
senseKey
,
senseValue
]
of
Object
.
entries
(
entry
.
science
.
senses
))
{
if
(
senseValue
.
Definitions
)
{
senseValue
.
Definitions
.
forEach
((
def
)
=>
{
definitions
.
push
({
id
:
def
.
id
||
'
ID non disponible
'
,
definition
:
def
.
definition
||
'
Définition non disponible
'
,
});
});
}
}
}
});
}
return
definitions
;
}
catch
(
error
)
{
console
.
error
(
'
Erreur lors de la récupération de la définition depuis le Wiktionnaire :
'
,
error
);
throw
error
;
}
}
// METTRE LES FONCTIONS GLOBALES
window
.
getUserLexicons
=
getUserLexicons
;
window
.
getLexiconEntries
=
getLexiconEntries
;
window
.
getWordInfo
=
getWordInfo
;
window
.
getDefinition
=
getDefinition
;
window
.
getWiktionaryDefinition
=
getWiktionaryDefinition
;
\ No newline at end of file
This diff is collapsed.
Click to expand it.
token.js
0 → 100644
+
23
−
0
View file @
77555e74
console
.
log
(
"
token.js chargé correctement
"
);
// Fonction pour lire le contenu du fichier token
async
function
readTokenFile
()
{
const
tokenFilePath
=
browser
.
runtime
.
getURL
(
'
token.txt
'
);
try
{
const
response
=
await
fetch
(
tokenFilePath
);
if
(
!
response
.
ok
)
{
throw
new
Error
(
`Erreur lors de la lecture du fichier token :
${
response
.
statusText
}
`
);
}
const
token
=
(
await
response
.
text
()).
trim
();
console
.
log
(
'
Token chargé :
'
,
token
);
return
token
;
}
catch
(
error
)
{
console
.
error
(
'
Erreur lors de la lecture du fichier token :
'
,
error
);
throw
error
;
}
}
// Exposer la fonction en tant que globale
window
.
readTokenFile
=
readTokenFile
;
This diff is collapsed.
Click to expand it.
token.txt
0 → 100644
+
1
−
0
View file @
77555e74
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJwcmlzbXMiLCJqdGkiOiJlMjk1ZmI0N2E4NGM4Y2Y2YTZmNDM2M2QxMGU0ZDMwNmU4NGYwOWQ1MDVkOTcxNzNkNzg1NTI4MWQxYzE3NjYyMzJkMGRjNmQ2ZGVkNWMyYSIsImlhdCI6MTczNzA4Njk5Ny4xMjcxMDgsIm5iZiI6MTczNzA4Njk5Ny4xMjcxMjksImV4cCI6MTczNzA5MDU5Ny4xMDEzMiwic3ViIjoiYXNvdW5hbGF0aCIsInNjb3BlcyI6WyJlbWFpbCIsInBzZXVkbyIsInV1aWQiXSwia2lkIjoiMSIsImN1c3RvbSI6eyJmb28iOiJiYXIifX0.E0ApQUZLsJShxq94jZOyt5XHZS4C-1xx4Nabzp5jUw0W7GE2FpzRhrUSC2DVXIu5oCw_LOh_uuv0kkBRD2YjsdFeCn3NBoJP_2sz8vJLzutfeR7Fl4MF166IM8RPYAT14werTQy82MUUXcvKli8E12y7SGM7qwwq5c7I_C3eNr2NJ_S-ivj_1JKZIv4vqsCR4NHk4MJC8Wmt0VDXBJuX5LUgAnvHBSxiEFdrQm7vuKg-nXk33biGYjMQAFepJhr-Oax2lvs-OwC-UuNOV87vpmr79umX4fRdA2USFOV8B_ro25LqJq6vugXAYCCLjXD4e0fLwDUhjzkFfXXslAqX7A
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment