Skip to content

Instantly share code, notes, and snippets.

View JohnRSim's full-sized avatar

John Sim JohnRSim

View GitHub Profile
@JohnRSim
JohnRSim / OCM_createDigitalAsset.js
Created September 13, 2022 13:36
Example function for creating digital assets on OCM
/**
* createDigitalAsset
* Creates a digital asset in OCM and returns reference
* @param {*} assetInfo product data
* @param {*} image image data
* @returns OCM digital asset data
*/
async function createDigitalAsset(assetInfo,image) {
console.log('[createDigitalAsset]',assetInfo);
@JohnRSim
JohnRSim / convertImgWithSharp.js
Created September 13, 2022 13:56
Convert Progressive Jpg to Lossless Jpg
/**
* convert
* Add any custom Image conversion logic
* @param {String} assetPath file path to convert image
* @returns {String} string path to converted image
*/
async function convert(assetPath) {
return new Promise(async (resolve, reject) => {
const outputPath = assetPath.replace(/media/g,'output');
@JohnRSim
JohnRSim / customComponentSnippet.js
Created October 4, 2022 13:40
In settings the custom binding "scsCompComponentImpl" doesn't get executed.. and SitesSDK.setHeight method does not exist?...
// set the iFrame height when we've fully rendered
ko.bindingHandlers.scsCompComponentImpl = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var body = document.body,
html = document.documentElement;
SitesSDK.setHeight(Math.max(
body.scrollHeight,
body.offsetHeight,
@JohnRSim
JohnRSim / settings.css
Last active October 4, 2022 14:29
Quick Gist example for tabset
/** Add Tab support **/
nav {
margin:10px 0px;
}
nav ul {
display: flex;
margin:0px;
padding:0px;
border-bottom:solid 1px #5B5E61;
@JohnRSim
JohnRSim / +server.js
Last active January 3, 2023 15:42
Sveltekit v1 Twitter oAuth1 with Lucia example
import { auth } from '$lib/server/lucia';
import { TwitterApi } from 'twitter-api-v2';
import { TWITTER_APPKEY, TWITTER_SECRET } from '$env/static/private';
//tmp
const twitterClient = new TwitterApi({
appKey: TWITTER_APPKEY,
appSecret: TWITTER_SECRET,
});
@JohnRSim
JohnRSim / OCM Content SDK Overview.md
Created June 28, 2023 13:07
Content SDK is a light-weight JavaScript wrapper

Installation

npm install @oracle/content-management-sdk

Using the SDK in NodeJS with ES6 import

import { contentSDK }  from '@oracle/content-management-sdk';
@JohnRSim
JohnRSim / getRenditionURL.md
Created June 28, 2023 13:15
Overview on OCM getRenditionURL

get the native rendition URL for this client

contentClient.getRenditionURL({
    id: 'CONTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1'
});

get the Thumbnail rendition URL for an image in JPEG format

contentClient.getRenditionURL({
@JohnRSim
JohnRSim / LoadingOCM_image.md
Created June 28, 2023 13:29
Quick sample of using OCM Content SDK to load in images
	import { createDeliveryClient } from '@oracle/content-management-sdk';
	
	//setup ocm server options
	const serverconfig = {
	  contentServer: SERVER_URL,
	  contentVersion: API_VERSION,
	  channelToken: CHANNEL_TOKEN,
	};
@JohnRSim
JohnRSim / ocm_srcset.js
Created June 28, 2023 13:56
OCM retrieve srcset rendition data for picture tag
/**
* Private method for adding the specified format rendition to the rendition string
*
* @param {Object} url - the url which contains the rendition strings
* @param {Object} rendition - the rendition field of the content sdk json object
* @param {String} formatstr - the format string type - either webp or jpg
*/
function addRendition(urls, rendition, formatstr) {
// Get the webp format field
const format = rendition.formats.filter((item) => item.format === `${formatstr}`)[0];
@JohnRSim
JohnRSim / OCM_injectPicture.js
Created June 28, 2023 14:35
Quick Example of returning asset data of an image parsing it to generate and inject picture tag
// Globals || ENV
const OCMURL = 'https://<instaance>-<cloud>.ocecdn.oraclecloud.com';
const APIVer = 'v1.1';
const channelToken = '9d4b5f18232740db944841a0e828a83b';
/**
* Custom err class for fetch
*/
class ResponseError extends Error {