ryoji-s 2 лет назад
Родитель
Сommit
4386f65cda

+ 1 - 9
apps/app/src/components/ReactMarkdownComponents/Attachment.tsx

@@ -1,8 +1,6 @@
 import React, { useCallback } from 'react';
 
-import { LocaleStringLang } from '@growi/core';
 import { UserPicture } from '@growi/ui/dist/components/User/UserPicture';
-import { useTranslation } from 'next-i18next';
 import prettyBytes from 'pretty-bytes';
 
 import { useSWRxAttachment } from '~/stores/attachment';
@@ -10,17 +8,11 @@ import { useDeleteAttachmentModal } from '~/stores/modal';
 
 import styles from './Attachment.module.scss';
 
-const getLocaleStringLocale = (language: string) => {
-  const mappedLocale = LocaleStringLang[language];
-  return mappedLocale || 'en-US';
-};
-
 export const Attachment: React.FC<{
   attachmentId: string,
   url: string,
   attachmentName: string
 }> = React.memo(({ attachmentId, url, attachmentName }) => {
-  const { i18n } = useTranslation();
   const { data: attachment, remove } = useSWRxAttachment(attachmentId);
   const { open: openDeleteAttachmentModal } = useDeleteAttachmentModal();
 
@@ -66,7 +58,7 @@ export const Attachment: React.FC<{
             <div className='d-flex align-items-center'>
               <UserPicture user={creator} size="sm"/>
               <span className='ml-2 text-muted'>
-                {new Date(createdAt).toLocaleString(getLocaleStringLocale(i18n.language))}
+                {new Date(createdAt).toLocaleString('en-US')}
               </span>
               <span className='ml-2 pl-2 border-left text-muted'>{prettyBytes(fileSize)}</span>
             </div>

+ 4 - 2
apps/app/src/services/renderer/remark-plugins/attachment.ts

@@ -1,3 +1,5 @@
+import path from 'path';
+
 import { Schema as SanitizeOption } from 'hast-util-sanitize';
 import { Plugin } from 'unified';
 import { Node } from 'unist';
@@ -12,11 +14,11 @@ const isAttachmentLink = (url: string) => {
 };
 
 const rewriteNode = (node: Node) => {
-  const pathName = (node.url as string).split('/');
+  const attachmentId = path.basename(node.url as string);
   const data = node.data ?? (node.data = {});
   data.hName = 'attachment';
   data.hProperties = {
-    attachmentId:  pathName[2],
+    attachmentId,
     url: node.url,
     attachmentName: (node.children as any)[0]?.value,
   };

+ 0 - 5
packages/core/src/interfaces/lang.ts

@@ -5,8 +5,3 @@ export const Lang = {
 } as const;
 export const AllLang = Object.values(Lang);
 export type Lang = typeof Lang[keyof typeof Lang];
-export const LocaleStringLang = {
-  en_US: 'en-US',
-  ja_JP: 'ja-JP',
-  zh_CN: 'zh-CN',
-} as const;