| 1 | import { |
| 2 | AutocompleteClipboardSnippet, |
| 3 | AutocompleteCodeSnippet, |
| 4 | AutocompleteSnippet, |
| 5 | AutocompleteSnippetType, |
| 6 | } from "../snippets/types"; |
| 7 | |
| 8 | const MAX_CLIPBOARD_AGE = 5 * 60 * 1000; |
| 9 | |
| 10 | const isValidClipboardSnippet = ( |
| 11 | snippet: AutocompleteClipboardSnippet, |
| 12 | ): boolean => { |
| 13 | const currDate = new Date(); |
| 14 | |
| 15 | const isTooOld = |
| 16 | currDate.getTime() - new Date(snippet.copiedAt).getTime() > |
| 17 | MAX_CLIPBOARD_AGE; |
| 18 | |
| 19 | return !isTooOld; |
| 20 | }; |
| 21 | |
| 22 | export const isValidSnippet = (snippet: AutocompleteSnippet): boolean => { |
| 23 | if (snippet.content.trim() === "") return false; |
| 24 | |
| 25 | if (snippet.type === AutocompleteSnippetType.Clipboard) { |
| 26 | return isValidClipboardSnippet(snippet); |
| 27 | } |
| 28 | |
| 29 | if ( |
| 30 | (snippet as AutocompleteCodeSnippet).filepath?.startsWith( |
| 31 | "output:extension-output-Continue.continue", |
| 32 | ) |
| 33 | ) { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | return true; |
| 38 | }; |