datocms-plugin-alt-text-ai 0.5.1 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "datocms-plugin-alt-text-ai",
3
- "version": "0.5.1",
4
- "private": false,
5
- "homepage": "https://github.com/marcelofinamorvieira/datocms-plugin-alt-text-ai",
3
+ "homepage": "https://github.com/datocms/plugins/blob/addMarceloPlugins/alt-text-ai/README.md",
4
+ "version": "0.5.2",
5
+ "author": "DatoCMS <support@datocms.com>",
6
6
  "description": "Generate alt texts for your assets in a single click",
7
7
  "keywords": [
8
8
  "datocms",
@@ -1,22 +1,18 @@
1
- import { Client, buildClient } from '@datocms/cma-client-browser';
1
+ import { Client, buildClient } from "@datocms/cma-client-browser";
2
2
  import {
3
3
  type FileFieldValue,
4
4
  RenderFieldExtensionCtx,
5
5
  } from "datocms-plugin-sdk";
6
- import { Button, Canvas, Spinner } from 'datocms-react-ui';
7
- import { isArray } from 'lodash';
8
- import get from 'lodash/get';
9
- import { useState } from 'react';
6
+ import { Button, Canvas, Spinner } from "datocms-react-ui";
7
+ import { isArray } from "lodash";
8
+ import get from "lodash/get";
9
+ import { useState } from "react";
10
10
 
11
11
  type PropTypes = {
12
12
  ctx: RenderFieldExtensionCtx;
13
13
  };
14
14
 
15
- async function fetchAlt(
16
- apiKey: string,
17
- client: Client,
18
- asset: FileFieldValue
19
- ) {
15
+ async function fetchAlt(apiKey: string, client: Client, asset: FileFieldValue) {
20
16
  const { url } = await client.uploads.find(asset.upload_id);
21
17
 
22
18
  // Instead of sending over files that are possibly too big or the wrong format, etc.,
@@ -26,11 +22,11 @@ async function fetchAlt(
26
22
  transformedUrl.searchParams.set("w", "1024");
27
23
 
28
24
  const result = await (
29
- await fetch('https://alttext.ai/api/v1/images', {
30
- method: 'POST',
25
+ await fetch("https://alttext.ai/api/v1/images", {
26
+ method: "POST",
31
27
  headers: {
32
- 'Content-Type': 'application/json',
33
- 'X-API-Key': apiKey ?? '',
28
+ "Content-Type": "application/json",
29
+ "X-API-Key": apiKey ?? "",
34
30
  },
35
31
  body: JSON.stringify({
36
32
  image: {
@@ -46,26 +42,28 @@ async function fetchAlt(
46
42
  async function generateAlts(
47
43
  currentFieldValue: unknown,
48
44
  ctx: RenderFieldExtensionCtx,
49
- setIsLoading: React.Dispatch<React.SetStateAction<boolean>>
45
+ setIsLoading: React.Dispatch<React.SetStateAction<boolean>>,
50
46
  ) {
51
47
  if (!ctx.currentUserAccessToken) {
52
- await ctx.alert('This plugin needs the currentUserAccessToken to function. Please give it that permission and try again.');
53
- return
48
+ await ctx.alert(
49
+ "This plugin needs the currentUserAccessToken to function. Please give it that permission and try again.",
50
+ );
51
+ return;
54
52
  }
55
53
 
56
54
  setIsLoading(true);
57
55
  try {
58
- const client = buildClient({ apiToken: ctx.currentUserAccessToken || '' });
56
+ const client = buildClient({ apiToken: ctx.currentUserAccessToken || "" });
59
57
  const isGallery = isArray(currentFieldValue);
60
58
  if (isGallery) {
61
- const existingAssets = currentFieldValue as FileFieldValue[]
59
+ const existingAssets = currentFieldValue as FileFieldValue[];
62
60
  const newAssets = [];
63
61
  for (const asset of existingAssets) {
64
- console.log('asset', asset);
62
+ console.log("asset", asset);
65
63
  const result = await fetchAlt(
66
64
  ctx.plugin.attributes.parameters.apiKey as string,
67
65
  client,
68
- asset
66
+ asset,
69
67
  );
70
68
 
71
69
  if (result.error_code) {
@@ -74,7 +72,6 @@ async function generateAlts(
74
72
  );
75
73
  }
76
74
 
77
-
78
75
  asset.alt = result.alt_text;
79
76
  newAssets.push(asset);
80
77
  }
@@ -85,7 +82,7 @@ async function generateAlts(
85
82
  const result = await fetchAlt(
86
83
  ctx.plugin.attributes.parameters.apiKey as string,
87
84
  client,
88
- assetValue
85
+ assetValue,
89
86
  );
90
87
 
91
88
  if (result.error_code) {
@@ -95,7 +92,6 @@ async function generateAlts(
95
92
  return;
96
93
  }
97
94
 
98
-
99
95
  assetValue.alt = result.alt_text;
100
96
  ctx.setFieldValue(ctx.fieldPath, assetValue);
101
97
  }
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$" />
5
- <orderEntry type="inheritedJdk" />
6
- <orderEntry type="sourceFolder" forTests="false" />
7
- </component>
8
- </module>
@@ -1,10 +0,0 @@
1
- <component name="InspectionProjectProfileManager">
2
- <profile version="1.0">
3
- <option name="myName" value="Project Default" />
4
- <inspection_tool class="JSIgnoredPromiseFromCall" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
5
- <inspection_tool class="UnnecessaryLocalVariableJS" enabled="false" level="WARNING" enabled_by_default="false">
6
- <option name="m_ignoreImmediatelyReturnedVariables" value="false" />
7
- <option name="m_ignoreAnnotatedVariables" value="false" />
8
- </inspection_tool>
9
- </profile>
10
- </component>
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="JavaScriptLibraryMappings">
4
- <includedPredefinedLibrary name="Node.js Core" />
5
- </component>
6
- </project>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/datocms-plugin-alt-text-ai.iml" filepath="$PROJECT_DIR$/.idea/datocms-plugin-alt-text-ai.iml" />
6
- </modules>
7
- </component>
8
- </project>
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="PrettierConfiguration">
4
- <option name="myConfigurationMode" value="MANUAL" />
5
- <option name="myRunOnReformat" value="true" />
6
- </component>
7
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>